diff --git a/Splat/ServiceLocation.cs b/Splat/ServiceLocation.cs index f34c49d1a..53f23a31c 100644 --- a/Splat/ServiceLocation.cs +++ b/Splat/ServiceLocation.cs @@ -180,18 +180,33 @@ public static IDisposable WithResolver(this IDependencyResolver resolver) return new ActionDisposable(() => Locator.Current = origResolver); } - + + public static void Register(this IMutableDependencyResolver This, Func 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(this IMutableDependencyResolver This, T value, string contract = null) + { + RegisterConstant(This, value, typeof(T), contract); + } + public static void RegisterLazySingleton(this IMutableDependencyResolver This, Func valueFactory, Type serviceType, string contract = null) { var val = new Lazy(valueFactory, LazyThreadSafetyMode.ExecutionAndPublication); This.Register(() => val.Value, serviceType, contract); } + public static void RegisterLazySingleton(this IMutableDependencyResolver This, Func valueFactory, string contract = null) + { + RegisterLazySingleton(This, () => valueFactory(), typeof(T), contract); + } + public static void InitializeSplat(this IMutableDependencyResolver This) { This.Register(() => new DefaultLogManager(), typeof(ILogManager));