Registration where both MappedToType and InjectionFactory are set is not supported Registration where both MappedToType and InjectionFactory are set is not supported asp.net asp.net

Registration where both MappedToType and InjectionFactory are set is not supported


When using an InjectionFactory, you should not set the explicit type to instantiate in RegisterType.

This should work:

container.RegisterType<DbContext>(new PerRequestLifetimeManager(), new InjectionFactory(x => CreateDBContext()));

You are delegating the job of instantiating the object to a custom factory, therefore the container does not need to know the type to instantiate.