Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMutableDependencyResolver mixins #128

Merged
merged 2 commits into from Jan 19, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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