更新后Autofac不工作 [英] Autofac not working after update

查看:239
本文介绍了更新后Autofac不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从3.2.1版本更新到Autofac.Mvc 3.3.0,我还更新了所有其他的包,包括EF,MVC,WebActivatorEx等,并更新它给我的控制器上的错误后

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

我把一个断点在我的初始化类我发现它竟然没有命中断点。我在我的项目已经单独依赖解析层,这是code初始化类

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));
        }
    }
}

请指导我这个问题。

推荐答案

引导程序项目仓的dll必须装入一个Web项目的dll,所以在引导程序项目>>选择属性>>选择Build选项卡>>改变输出路径>>到Web项目斌(例如:.. \\ myApp.web \\ BIN)

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)

这篇关于更新后Autofac不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆