You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A lot of the APIs in the DNX frameworks are fluent. I was wondering if there would be any desire to have a method like the following:
using Autofac;
using Autofac.Dnx;
using System;
namespace Microsoft.Framework.DependencyInjection
{
public static class AutofacExtensions
{
public static IServiceProvider AddAutofac<T>(this IServiceCollection collection)
where T : Module, new()
{
var builder = new ContainerBuilder();
builder.RegisterModule<T>();
builder.Populate(collection);
var container = builder.Build();
return container.Resolve<IServiceProvider>();
}
}
}
This way, a meta-module that contains all the registrations for the application can be loaded like this:
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc();
return services.AddAutofac<TestModule>();
}
This does not require any usings to be added and the Startup class can be kept simpler than doing the registrations in it.
The text was updated successfully, but these errors were encountered:
While this is an interesting idea, I think we will probably not be implementing this in core Autofac.
It's nice to be able to register all of your dependencies in one module, but in practice I've seen that most apps don't have just one central module registration.
We had a similar pattern in the OWIN integration package and we're finding that folks value control over exactly when things happen - registrations of dependencies, calling Populate, that sort of thing.
It sounds like something you may want to add to a project-specific extensions library or possibly create a public Autofac extensions library and publish it for the community to use.
A lot of the APIs in the DNX frameworks are fluent. I was wondering if there would be any desire to have a method like the following:
This way, a meta-module that contains all the registrations for the application can be loaded like this:
This does not require any usings to be added and the
Startup
class can be kept simpler than doing the registrations in it.The text was updated successfully, but these errors were encountered: