在ASP.NET MVC5中,我只有 Saver
类 public class Saver
{
private readonly ResponseModel _model;
[Dependency]
public SomeService SomeService { get; set; }
public Saver(ResponseModel model)
{
_model= estateModel;
}
public void Save(){
// here SomeService is null
}
}
在UnityConfig.cs中我有这个
container.RegisterType<SomeService >(new TransientLifetimeManager());
然后在UnityMvcActivator.cs中我有了这个
IUnityContainer container = UnityConfig.GetConfiguredContainer();
FilterProviders.Providers.Remove(FilterProviders.Providers.OfType<FilterAttributeFilterProvider>().First());
FilterProviders.Providers.Add(new UnityFilterAttributeFilterProvider(container));
DependencyResolver.SetResolver(new UnityDependencyResolver(container));
// TODO: Uncomment if you want to use PerRequestLifetimeManager
DynamicModuleUtility.RegisterModule(typeof(UnityPerRequestHttpModule));
我该怎么做才能解决此错误。为什么要在控制器中注入工作,而不是在其他类中,这不是控制器?