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}",
serviceType.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: