Self-Registering Libraries with Autofac 4 and vNext

后端 未结 2 2047
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-18 10:24

i\'d like to create a Plugin Enviroment for my ASP.Net 5.0 / MVC 6 Application. I\'m using Autofac as IOC Container and i like to load the Plugins (Class Libraries) from the

2条回答
  •  时光说笑
    2020-12-18 10:42

    It's a shame that ConfigureServices is not injectable, that would make this a lot easier.

    Looking at the code you should be safe to replace the IServiceProvider inside Configure(...) instead of inside ConfigureServices(...) and get the intended behavior. ApplicationServices is setable.

    In your UseAutofac method you should be able to do something like:

    public static IApplicationBuilder UseAutofac( [NotNull] this IApplicationBuilder applicationBuilder )
    {
        IAutofacResolver autofacResolver = applicationBuilder.GetService();
        ILibraryManager libraryManager = applicationBuilder.GetService();
    
        autofacResolver.RegisterLibraryModules( libraryManager);
        applicationBuilder.ApplicationServices = autofacResolver.Resolve();
    
        return applicationBuilder;
    }
    

提交回复
热议问题