• autofac无法解析一例


    在asp.net mvc分项目开发中,如果类库位于其他的项目中,则必须在global中对其他项目的类库进行注册,否则会报“

    None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'SportsStore.WebUI.Controllers.ListController' can be invoked with the available services and parameters:
    Cannot resolve parameter 'SportsStore.Domain.Abstrace.IProductRepository productRepository' of constructor 'Void .ctor(SportsStore.Domain.Abstrace.IProductRepository)'.”

     解决方案很简单,注册就行。

    ContainerBuilder builder = new ContainerBuilder();
                builder.RegisterControllers(Assembly.GetExecutingAssembly());
                builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()).AsImplementedInterfaces();
                //注册类库程序集
                builder.RegisterAssemblyTypes(Assembly.Load("SportsStore.Domain")).AsImplementedInterfaces();
    
                var container = builder.Build();
                DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

    注:通过nuget 安装Autofac.mvc4

  • 相关阅读:
    判断奇偶数2
    判断奇偶数
    15.09.29
    .
    Java代码
    Handler 接收Parcelable ArrayList时返回空的错误
    Android Binder设计与实现
    xml解析代码示例
    解析rss和atom文件出现乱码问题
    使用Html.fromHtml将html格式字符串应用到textview上面
  • 原文地址:https://www.cnblogs.com/superfeeling/p/7464284.html
Copyright © 2020-2023  润新知