Getting autofac to work with mvc6 beta5

前端 未结 1 1529
别那么骄傲
别那么骄傲 2021-01-02 11:09

I am trying to get autofac working with an mvc6 application I am working on. I found this blog article however it seems to be a little dated. It looks like its using the bet

相关标签:
1条回答
  • 2021-01-02 11:47

    For anyone who would be looking how to get AutoFac running below configuration allowed me to use it in beta6

    Below is snippet of project.json

      "dependencies": {
    "Autofac": "4.0.0-beta6-110",
    "Autofac.Framework.DependencyInjection": "4.0.0-beta6-110",
    "Microsoft.AspNet.Mvc": "6.0.0-beta6",
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta6",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-beta6",
    "Microsoft.AspNet.StaticFiles": "1.0.0-beta6"
    },
    

    And then part of startup.cs

        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
    
            //create Autofac container build
            var builder = new ContainerBuilder();
    
            //populate the container with services here..
            builder.RegisterType<DemoService>().As<IProjectDemo>();
            builder.Populate(services);
    
            //build container
            var container = builder.Build();
    
            //return service provider
            return container.ResolveOptional<IServiceProvider>();
        }
    

    As mentioned by @peco make sure you have

    using Autofac.Framework.DependencyInjection
    

    And that got me going notime with AutoFac :) Hope this helps!

    0 讨论(0)
提交回复
热议问题