What should I register with my IoC container?
If you are going to use an IoC container, regardless of which one, here is what needs to be registered, and some thoughts about object lifetime. If we do not specify a lifetime, you can assume that singleton is acceptable.
Highway.Data
IRepository
should resolve toRepository
on either a transient (new every request) or per web request (if you’re in a website) object lifetime.IEventManager
should resolve toEventManager
ILog
should resolve to either a Common.Logging implementation for your chosen logger, or an instance ofNoOpLogger
from Common.Logging.
Highway.Data.EntityFramework
IDataContext
should resolve toDataContext
on either a transient (new every request).- Your IoC will need to inject a connection string, named
connectionString
to the constructor, in whatever way such primitive dependencies are handled by your container.
- Your IoC will need to inject a connection string, named
IMappingConfiguration
should resolve to a type you have created that implements this interface and maps all of your entities.IContextConfiguration
should resolve toDefaultContextConfiguration
or a class you’ve created should you need to change how the Context is configured from our defaults.
Highway.Data.NHibernate
IDataContext
should resolve toDataContext
on either a transient (new every request).ISession
should resolve to a call to your configuredISessionFactory
. These are standard NHibernate interfaces, and you should follow their guidance regarding object lifetime.
Highway.Data.RavenDb
IDataContext
should resolve toDataContext
on either a transient (new every request).IDocumentSession
should resolve to a call to your configuredIDocumentStore
. These are standard RavenDb interfaces, and you should follow their guidance regarding object lifetime.