I need to use multiple connections string in my ASP.NET MVC application. How I can to do it? Now i'm registering connection as following:
builder.RegisterType<SqlConnection>().WithParameter(
"connectionString",
WebConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString)
.InstancePerLifetimeScope()
.ExternallyOwned();
builder.Register(c => new ContextDataContext(c.Resolve<SqlConnection>())).InstancePerDependency();
You can register multiple instances of a given type by name:
From Autofac tutorial:
builder.Register<OnlineState>().Named<IDeviceState>("online");
To retrieve a named service, the ResolveNamed() method is used:
var r = container.ResolveNamed<IDeviceState>("online");
http://autofac.readthedocs.org/en/latest/advanced/keyed-services.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With