Skip to content

Dependency Injection

Sergey Akopov edited this page Oct 11, 2016 · 3 revisions

If you'd like to use a Dependency Injection container, you'll need to correctly register the concrete types for IDbConnectionFactory, IAmbientDbContextFactory and IAmbientDbContextLocator interfaces.

The example below is using SimpleInjector, however you can easily apply the same pattern to all major DI containers.

Container container = new Container();

container.RegisterSingleton<IDbConnectionFactory>(() => new SqlServerConnectionFactory("your connection string"));
container.RegisterSingleton<IAmbientDbContextFactory, AmbientDbContextFactory>();
container.Register<IAmbientDbContextLocator, AmbientDbContextLocator>();
Clone this wiki locally