Autofac not working after update

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 10:42:07

问题


I have updated Autofac.Mvc from version 3.2.1 to 3.3.0, i also updated all other packages including EF, MVC, WebActivatorEx etc and after update it is giving error on my controller

no parameterless constructor defined for this object

I put a breakpoint in my initialization class and i found that it is not even hitting the breakpoint. I've a separate dependency resolution layer in my project and this is the code for initialization class

[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(IocConfig), "RegisterDependencies")]

namespace MyApp.Bootstrapper
{
    public class IocConfig
    {
        public static void RegisterDependencies()
        {
            var builder = new ContainerBuilder();
            const string nameOrConnectionString = "name=AppContext";
            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            builder.RegisterModule<AutofacWebTypesModule>();
            builder.RegisterGeneric(typeof(EntityRepository<>)).As(typeof(IRepository<>)).InstancePerHttpRequest();
            builder.RegisterGeneric(typeof(Service<>)).As(typeof(IService<>)).InstancePerHttpRequest();
            builder.RegisterType(typeof(UnitOfWork)).As(typeof(IUnitOfWork)).InstancePerHttpRequest();
            builder.Register<IEntitiesContext>(b =>
            {
                var logger = b.Resolve<ILogger>();
                var context = new AspnetIdentityWithOnionContext(nameOrConnectionString, logger);
                return context;
            }).InstancePerHttpRequest();
            builder.Register(b => NLogLogger.Instance).SingleInstance();
            builder.RegisterModule(new IdentityModule());

            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
    }
}

Please guide me with this.


回答1:


The bootstrapper project bin dlls must be loaded with a web project dll ,so in the bootstrapper project >> select properties >> select build tab >> change output path to >> web project bin (ex:..\myApp.web\bin)



来源:https://stackoverflow.com/questions/30818756/autofac-not-working-after-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!