I'm using Ninject as IoC and I'm following a tutorial to convert the ASP.NET Owin security default methods to follow the dependency injection pattern.
My database context, MongoDB in this case, is binded like this:
kernel.Bind<IMongoContext>().To<MongoContext>().InSingletonScope();
Currently, my security module (non dependency injection) is like this:
var users = MongoContext.Create().GetCollection<ApplicationUser>();
var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(users));
I'd like to resolve UserStore like I've seen in this Unity resolution:
container.RegisterType<IUserStore<ApplicationUser>, UserStore<ApplicationUser>>(
new InjectionConstructor(typeof(ApplicationDbContext)));
Well, the above code is using Entity Framework, in my case, it would be similar with my MongoContext.
I think It would be something similar to
kernel.Bind<IUserStore>.To<UserStore>().WithConstructorArgument(/*some extra option to pass a resolve of my MongoContext*/)
So I need to know how to pass the resolved MongoContext to the UserStore bind.
EDIT: IUserStore and UserStore are System classes, not mine.
UserStore
a constructor which injects theIMongoContext
? This would meanWithConstructorArgument()
would not be necessary... – timothyclifford