Mam problem z Ninject.Ninject + ASP.NET MVC + InRequestScope
Moi wiążące zasady:
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>());
Gdzie
SQLServer, ISphinxQLServer i IMySQLServer to:
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;
}
}
Chcę, aby każdy żądanie użytkownika do mojego ASP.NET MVC miejscu tworzy pojedynczy SQLServer, pojedynczy ISQLLogger i pojedyncze DatabaseConnections. Ale moje rozwiązanie nie działa. Co ja robię źle? . = (
Dzięki, pomogło mi to z podobnym problemem. –