Tengo un problema con el Ninject.Ninject + ASP.NET MVC + InRequestScope
Mis reglas de enlace:
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>());
Dónde
SQL Server, ISphinxQLServer y IMySQLServer son:
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;
}
}
Quiero que cada petición de usuario a mi sitio asp.net mvc crea un solo SQLServer, un solo ISQLLogger y una sola DatabaseConnections. Pero mi solución no funciona. ¿Qué estoy haciendo mal? . = (
Gracias, esto me ayudó con un problema similar. –