6
我對Ninject有問題。Ninject + ASP.NET MVC + InRequestScope
我有約束力的規則:
this.Bind<ISphinxQLServer>().To<SQLServer>();
this.Bind<IMySQLServer>().To<SQLServer>();
this.Bind<ISQLLogger>().To<StandardSQLLogger>()
.InRequestScope();
this.Bind<DatabaseConnections>()
.ToMethod(x => ConnectionFactory.GetConnections())
.InRequestScope();
this.Bind<SQLServer>().ToSelf()
.InRequestScope()
.WithConstructorArgument("connections", Kernel.Get<DatabaseConnections>())
.WithConstructorArgument("logger", Kernel.Get<ISQLLogger>());
凡
SQLSERVER,ISphinxQLServer和IMySQLServer是:
public class SQLServer: ISphinxQLServer, IMySQLServer
{
public DatabaseConnections Connections { get; internal set; }
public ISQLLogger Logger { get; internal set; }
public SQLServer(DatabaseConnections connections)
{
this.Connections = connections;
}
public SQLServer(DatabaseConnections connections, ISQLLogger logger)
{
this.Connections = connections;
this.Logger = logger;
}
}
我想每一個用戶請求我的asp.net mvc的網站創建一個SQLServer,一個ISQLLogger和一個DatabaseConnections。但我的解決方案不工作。我究竟做錯了什麼? =(
謝謝,這幫助我解決了類似的問題。 – 2011-03-24 18:38:13