Skip to content

Commit

Permalink
Merge pull request #128 from kentcb/mutabledependencyresolver-mixins
Browse files Browse the repository at this point in the history
IMutableDependencyResolver generic mixins.
  • Loading branch information
kentcb committed Jan 19, 2016
2 parents 733fb1e + 6c4e9eb commit d7a80eb
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Splat/ServiceLocation.cs
Expand Up @@ -180,18 +180,33 @@ public static IDisposable WithResolver(this IDependencyResolver resolver)

return new ActionDisposable(() => Locator.Current = origResolver);
}


public static void Register<T>(this IMutableDependencyResolver This, Func<T> factory, string contract = null)
{
This.Register(() => factory(), typeof(T), contract);
}

public static void RegisterConstant(this IMutableDependencyResolver This, object value, Type serviceType, string contract = null)
{
This.Register(() => value, serviceType, contract);
}

public static void RegisterConstant<T>(this IMutableDependencyResolver This, T value, string contract = null)
{
RegisterConstant(This, value, typeof(T), contract);
}

public static void RegisterLazySingleton(this IMutableDependencyResolver This, Func<object> valueFactory, Type serviceType, string contract = null)
{
var val = new Lazy<object>(valueFactory, LazyThreadSafetyMode.ExecutionAndPublication);
This.Register(() => val.Value, serviceType, contract);
}

public static void RegisterLazySingleton<T>(this IMutableDependencyResolver This, Func<T> valueFactory, string contract = null)
{
RegisterLazySingleton(This, () => valueFactory(), typeof(T), contract);
}

public static void InitializeSplat(this IMutableDependencyResolver This)
{
This.Register(() => new DefaultLogManager(), typeof(ILogManager));
Expand Down

0 comments on commit d7a80eb

Please sign in to comment.