Skip to content

Instantly share code, notes, and snippets.

@jfromaniello
Created July 31, 2010 14:33
Show Gist options
  • Save jfromaniello/502240 to your computer and use it in GitHub Desktop.
Save jfromaniello/502240 to your computer and use it in GitHub Desktop.
public class DelegateComponentLoader : ILazyComponentLoader
{
public DelegateComponentLoader(Func<Context, IRegistration> action)
{
this.action = action;
}
public IRegistration Load(string key, Type service);
{
return action(new Context(key, service));
}
}
public class Context
{
public Context (string key, type service)
{
Key = key; Service = service;
}
public string Key{get; private set;}
public Type Service{get; private set;
}
public static class ContainerExtensions
{
public static void AddMissingInstanceContructor(this IWindsorContainer container, Func<Context, IRegistration> context)
{
container.Kernel.AddComponent(typeof(ILazyComponentLoader), new DelegateComponentLoader(context));
}
}
//usage:
container.AddMissingConstructor(context => Component.For(context.Type).Instance(new Something(context.Key));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment