Take the following useless program:
class Program
{
static void Main(string[] args)
{
IUnityContainer unityContainer = new UnityContainer();
Krzysztof don't be afraid to link to your own blog here :) http://devlicious.com/blogs/krzysztof_kozmic/archive/2009/11/16/castle-windsor-lazy-loading.aspx
Also, I found this simple implementation useful in my WPF app, remove the string contraint and you are close to the general case
public class ViewModelLoader : Castle.MicroKernel.Resolvers.ILazyComponentLoader {
public IRegistration Load(string key, Type service)
{
if (service == null)
return null;
if (service.Name.EndsWith("ViewModel", StringComparison.CurrentCultureIgnoreCase))
return Component.For(service).Named(key);
else
return null;
}
}