Is this expected behaviour of the MVC IDependencyResolver?
I have implemented a System.Web.Mvc.IDependencyResolver which looks up services registered with Castle Windsor. My GetService(Type serviceType) implementation is below (for MVC3 RC2).
public object GetService(Type serviceType)
{
object service = null;
try
{
service = _container.Resolve(serviceType);
}
catch(Exception ex)
{
Logger.Warn("Could not resolve service-type {0} via {1}",
service开发者_运维百科Type.Name, _resolverName);
}
return service;
}
This works well, but I have a question about warnings that I see in my logs (I log all exceptions as 'Warn' - see the code above):
WARN Default [] - Could not resolve service-type Index_cshtml via
WindsorDependencyResolver
WARN Default [] - Could not resolve service-type RegistrationForm_cshtml via
WindsorDependencyResolver
WARN Default [] - Could not resolve service-type LoginForm_cshtml via
WindsorDependencyResolver
These are views. Is this expected behaviour? If so, why is the dependency resolver asked to find views? If not, what should I be doing to resolve this?
Note that I haven't registered an instance of IViewPageActivator (see the warning, below) which should signal to the framework that views should be resolved in the default manner. Why do I still see requests for views through my dependency resolver?
WARN Default [] - Could not resolve service-type IViewPageActivator via
WindsorDependencyResolver
IDependencyResolver in MVC3 could resolve views as well as other types. This could be very useful in case when you need to change view implementations for example when you are unit-testing your solution. More details: http://bradwilson.typepad.com/blog/2010/10/service-location-pt11-view-page-activator.html:
The logic in BuildManagerCompiledView consults the dependency resolver, calling GetSerivce(typeof(IViewPageActivator)) and using the provided service when present. If there is no IViewPageActivator present in the dependency resolver, we will then ask the dependency resolver to create the concrete view page type by calling GetService(viewPageType). If the dependency resolver also fails to create the concrete view page type, we finally fall back to the MVC 2 behavior of using Activator.CreateInstance to create the view page type.
精彩评论