在application_start()
我有以下代碼。 當賬戶控制器被創建時,我得到了無參數的構造函數錯誤。 AccountController沒有無參數的構造函數。看來autofac不再配置?無參數構造函數錯誤。 (升級到autofac 3)
帳戶控制器期望以下。
public AccountController(IFlexMembershipProvider membership, IFlexOAuthProvider openAuth)
我不知道爲什麼autofac沒有注入相關性?
var builder = new ContainerBuilder();
builder.RegisterType<DataContext>()
.As<IRepository>()
.As<DbContext>().InstancePerLifetimeScope();
builder.RegisterType<FlexMembershipProvider>().As<IFlexMembershipProvider>();
builder.RegisterType<FlexMembershipProvider>().As<IFlexOAuthProvider>();
builder.RegisterType<FlexRoleProvider>().As<IFlexRoleProvider>();
builder.RegisterType<UserStorage>().As<IFlexUserStore>().InstancePerLifetimeScope();
builder.RegisterType<RoleStorage>().As<IFlexRoleStore>().InstancePerLifetimeScope();
builder.RegisterType<DefaultSecurityEncoder>().As<ISecurityEncoder>().SingleInstance();
builder.RegisterType<AspnetEnvironment>().As<IApplicationEnvironment>();
builder.RegisterType<InvestorService>().As<IInvestorService>();
builder.RegisterType<InvestmentService>().As<IInvestmentService>();
builder.RegisterType<BrokerService>().As<IBrokerService>().As<IListService<Broker>>();
builder.RegisterType<PortfolioManagerService>().As<IListService<PortfolioManager>>();
builder.RegisterModelBinderProvider();
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
我有問題。 – IamStalker 2013-02-17 08:27:41