Skip to content

Instantly share code, notes, and snippets.

@omares
Last active August 29, 2015 14:23
Show Gist options
  • Save omares/43d026488a846f105e13 to your computer and use it in GitHub Desktop.
Save omares/43d026488a846f105e13 to your computer and use it in GitHub Desktop.
// SomeClass is stored as typeof in a var
Func<SomeClass> factory = () => Container.GetInstance<SomeClass>();
Container.Register<Lazy<SomeClass>>(() => new Lazy<SomeClass>(factory));
var lazy = typeof(Lazy<>).MakeGenericType(type);
var method = typeof(SimpleInjectorExtensions).GetTypeInfo().GetDeclaredMethod("RegisterLazy").MakeGenericMethod(lazy);
method.Invoke(container, new object[] {container });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment