【发布时间】:2011-05-28 10:19:44
【问题描述】:
我的 Ninject 有问题。
我的绑定规则:
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。但我的解决方案不起作用。我究竟做错了什么? =(
【问题讨论】:
标签: asp.net-mvc ninject