更新后Autofac不工作 [英] Autofac not working after update
问题描述
我从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屋!