I'm wondering what the best practices is here. I need to construct a DbContext for my multi tenanted application, so I have made a Dependency provider like this:
public class TenantContextFactoryProvider : Provider<DbContext>
{
protected override DbContext CreateInstance(IContext context)
{
var tenant = // How to get the tenant through ninject??
return new DbContext(tenant.ConnectionString);
}
}
I need ninject to resolve the tenant dependency, but I'm not sure how to do this?
This is a bit embarassing, but I guess if it can happen to me, it can happen to someone else as well.
I forgot to include
using Ninject
, which is why the extension methodcontext.Kernel.Get
wasn't showing up, in IntelliSense.So my code ended up looking like this:
While service locator certainly works, constructor injection is another choice.