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

Fluent API for IContainerRegistry fixes #1677 #1705

Merged
merged 1 commit into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions Source/Prism/Ioc/IContainerRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ namespace Prism.Ioc
{
public interface IContainerRegistry
{
void RegisterInstance(Type type, object instance);
IContainerRegistry RegisterInstance(Type type, object instance);

void RegisterInstance(Type type, object instance, string name);
IContainerRegistry RegisterInstance(Type type, object instance, string name);

void RegisterSingleton(Type from, Type to);
IContainerRegistry RegisterSingleton(Type from, Type to);

void RegisterSingleton(Type from, Type to, string name);
IContainerRegistry RegisterSingleton(Type from, Type to, string name);

void Register(Type from, Type to);
IContainerRegistry Register(Type from, Type to);

void Register(Type from, Type to, string name);
IContainerRegistry Register(Type from, Type to, string name);

bool IsRegistered(Type type);

Expand Down
48 changes: 24 additions & 24 deletions Source/Prism/Ioc/IContainerRegistryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,64 @@ namespace Prism.Ioc
{
public static class IContainerRegistryExtensions
{
public static void RegisterInstance<TInterface>(this IContainerRegistry containerRegistry, TInterface instance)
public static IContainerRegistry RegisterInstance<TInterface>(this IContainerRegistry containerRegistry, TInterface instance)
{
containerRegistry.RegisterInstance(typeof(TInterface), instance);
return containerRegistry.RegisterInstance(typeof(TInterface), instance);
}

public static void RegisterInstance<TInterface>(this IContainerRegistry containerRegistry, TInterface instance, string name)
public static IContainerRegistry RegisterInstance<TInterface>(this IContainerRegistry containerRegistry, TInterface instance, string name)
{
containerRegistry.RegisterInstance(typeof(TInterface), instance, name);
return containerRegistry.RegisterInstance(typeof(TInterface), instance, name);
}

public static void RegisterSingleton(this IContainerRegistry containerRegistry, Type type)
public static IContainerRegistry RegisterSingleton(this IContainerRegistry containerRegistry, Type type)
{
containerRegistry.RegisterSingleton(type, type);
return containerRegistry.RegisterSingleton(type, type);
}

public static void RegisterSingleton<TFrom, TTo>(this IContainerRegistry containerRegistry) where TTo : TFrom
public static IContainerRegistry RegisterSingleton<TFrom, TTo>(this IContainerRegistry containerRegistry) where TTo : TFrom
{
containerRegistry.RegisterSingleton(typeof(TFrom), typeof(TTo));
return containerRegistry.RegisterSingleton(typeof(TFrom), typeof(TTo));
}

public static void RegisterSingleton<TFrom, TTo>(this IContainerRegistry containerRegistry, string name) where TTo : TFrom
public static IContainerRegistry RegisterSingleton<TFrom, TTo>(this IContainerRegistry containerRegistry, string name) where TTo : TFrom
{
containerRegistry.RegisterSingleton(typeof(TFrom), typeof(TTo), name);
return containerRegistry.RegisterSingleton(typeof(TFrom), typeof(TTo), name);
}

public static void RegisterSingleton<T>(this IContainerRegistry containerRegistry)
public static IContainerRegistry RegisterSingleton<T>(this IContainerRegistry containerRegistry)
{
containerRegistry.RegisterSingleton(typeof(T));
return containerRegistry.RegisterSingleton(typeof(T));
}

public static void Register(this IContainerRegistry containerRegistry, Type type)
public static IContainerRegistry Register(this IContainerRegistry containerRegistry, Type type)
{
containerRegistry.Register(type, type);
return containerRegistry.Register(type, type);
}

public static void Register<T>(this IContainerRegistry containerRegistry)
public static IContainerRegistry Register<T>(this IContainerRegistry containerRegistry)
{
containerRegistry.Register(typeof(T));
return containerRegistry.Register(typeof(T));
}

public static void Register(this IContainerRegistry containerRegistry, Type type, string name)
public static IContainerRegistry Register(this IContainerRegistry containerRegistry, Type type, string name)
{
containerRegistry.Register(type, type, name);
return containerRegistry.Register(type, type, name);
}

public static void Register<T>(this IContainerRegistry containerRegistry, string name)
public static IContainerRegistry Register<T>(this IContainerRegistry containerRegistry, string name)
{
containerRegistry.Register(typeof(T), name);
return containerRegistry.Register(typeof(T), name);
}

public static void Register<TFrom, TTo>(this IContainerRegistry containerRegistry) where TTo : TFrom
public static IContainerRegistry Register<TFrom, TTo>(this IContainerRegistry containerRegistry) where TTo : TFrom
{
containerRegistry.Register(typeof(TFrom), typeof(TTo));
return containerRegistry.Register(typeof(TFrom), typeof(TTo));
}

public static void Register<TFrom, TTo>(this IContainerRegistry containerRegistry, string name) where TTo : TFrom
public static IContainerRegistry Register<TFrom, TTo>(this IContainerRegistry containerRegistry, string name) where TTo : TFrom
{
containerRegistry.Register(typeof(TFrom), typeof(TTo), name);
return containerRegistry.Register(typeof(TFrom), typeof(TTo), name);
}

public static bool IsRegistered<T>(this IContainerRegistry containerRegistry)
Expand Down
18 changes: 12 additions & 6 deletions Source/Windows10/Prism.DryIoc.Windows/DryIocContainerExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,40 @@ public DryIocContainerExtension(IContainer container)

public void FinalizeExtension() { }

public void RegisterInstance(Type type, object instance)
public IContainerRegistry RegisterInstance(Type type, object instance)
{
Instance.UseInstance(type, instance);
return this;
}

public void RegisterInstance(Type type, object instance, string name)
public IContainerRegistry RegisterInstance(Type type, object instance, string name)
{
Instance.UseInstance(type, instance, serviceKey: name);
return this;
}

public void RegisterSingleton(Type from, Type to)
public IContainerRegistry RegisterSingleton(Type from, Type to)
{
Instance.Register(from, to, Reuse.Singleton);
return this;
}

public void RegisterSingleton(Type from, Type to, string name)
public IContainerRegistry RegisterSingleton(Type from, Type to, string name)
{
Instance.Register(from, to, Reuse.Singleton, serviceKey: name);
return this;
}

public void Register(Type from, Type to)
public IContainerRegistry Register(Type from, Type to)
{
Instance.Register(from, to);
return this;
}

public void Register(Type from, Type to, string name)
public IContainerRegistry Register(Type from, Type to, string name)
{
Instance.Register(from, to, serviceKey: name);
return this;
}

public object Resolve(Type type)
Expand Down
18 changes: 12 additions & 6 deletions Source/Windows10/Prism.Unity.Windows/UnityContainerExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,40 @@ public sealed class UnityContainerExtension : IContainerExtension<IUnityContaine

public void FinalizeExtension() { }

public void RegisterInstance(Type type, object instance)
public IContainerRegistry RegisterInstance(Type type, object instance)
{
Instance.RegisterInstance(type, instance);
return this;
}

public void RegisterInstance(Type type, object instance, string name)
public IContainerRegistry RegisterInstance(Type type, object instance, string name)
{
Instance.RegisterInstance(type, name, instance);
return this;
}

public void RegisterSingleton(Type from, Type to)
public IContainerRegistry RegisterSingleton(Type from, Type to)
{
Instance.RegisterSingleton(from, to);
return this;
}

public void RegisterSingleton(Type from, Type to, string name)
public IContainerRegistry RegisterSingleton(Type from, Type to, string name)
{
Instance.RegisterSingleton(from, to, name);
return this;
}

public void Register(Type from, Type to)
public IContainerRegistry Register(Type from, Type to)
{
Instance.RegisterType(from, to);
return this;
}

public void Register(Type from, Type to, string name)
public IContainerRegistry Register(Type from, Type to, string name)
{
Instance.RegisterType(from, to, name);
return this;
}

public object Resolve(Type type)
Expand Down
18 changes: 12 additions & 6 deletions Source/Wpf/Prism.DryIoc.Wpf/Ioc/DryIocContainerExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,40 @@ public DryIocContainerExtension(IContainer container)

public void FinalizeExtension() { }

public void RegisterInstance(Type type, object instance)
public IContainerRegistry RegisterInstance(Type type, object instance)
{
Instance.UseInstance(type, instance);
return this;
}

public void RegisterInstance(Type type, object instance, string name)
public IContainerRegistry RegisterInstance(Type type, object instance, string name)
{
Instance.UseInstance(type, instance, serviceKey: name);
return this;
}

public void RegisterSingleton(Type from, Type to)
public IContainerRegistry RegisterSingleton(Type from, Type to)
{
Instance.Register(from, to, Reuse.Singleton);
return this;
}

public void RegisterSingleton(Type from, Type to, string name)
public IContainerRegistry RegisterSingleton(Type from, Type to, string name)
{
Instance.Register(from, to, Reuse.Singleton, serviceKey: name);
return this;
}

public void Register(Type from, Type to)
public IContainerRegistry Register(Type from, Type to)
{
Instance.Register(from, to);
return this;
}

public void Register(Type from, Type to, string name)
public IContainerRegistry Register(Type from, Type to, string name)
{
Instance.Register(from, to, serviceKey: name);
return this;
}

public object Resolve(Type type)
Expand Down
18 changes: 12 additions & 6 deletions Source/Wpf/Prism.Ninject.Wpf/Ioc/NinjectContainerExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,40 @@ public NinjectContainerExtension(IKernel kernel)

public void FinalizeExtension() { }

public void RegisterInstance(Type type, object instance)
public IContainerRegistry RegisterInstance(Type type, object instance)
{
Instance.Bind(type).ToConstant(instance);
return this;
}

public void RegisterInstance(Type type, object instance, string name)
public IContainerRegistry RegisterInstance(Type type, object instance, string name)
{
Instance.Bind(type).ToConstant(instance).Named(name);
return this;
}

public void RegisterSingleton(Type from, Type to)
public IContainerRegistry RegisterSingleton(Type from, Type to)
{
Instance.Bind(from).To(to).InSingletonScope();
return this;
}

public void RegisterSingleton(Type from, Type to, string name)
public IContainerRegistry RegisterSingleton(Type from, Type to, string name)
{
Instance.Bind(from).To(to).InSingletonScope().Named(name);
return this;
}

public void Register(Type from, Type to)
public IContainerRegistry Register(Type from, Type to)
{
Instance.Bind(from).To(to).InTransientScope();
return this;
}

public void Register(Type from, Type to, string name)
public IContainerRegistry Register(Type from, Type to, string name)
{
Instance.Bind(from).To(to).InTransientScope().Named(name);
return this;
}

public object Resolve(Type type)
Expand Down
18 changes: 12 additions & 6 deletions Source/Wpf/Prism.Unity.Wpf/Ioc/UnityContainerExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,40 @@ public class UnityContainerExtension : IContainerExtension<IUnityContainer>

public void FinalizeExtension() { }

public void RegisterInstance(Type type, object instance)
public IContainerRegistry RegisterInstance(Type type, object instance)
{
Instance.RegisterInstance(type, instance);
return this;
}

public void RegisterInstance(Type type, object instance, string name)
public IContainerRegistry RegisterInstance(Type type, object instance, string name)
{
Instance.RegisterInstance(type, name, instance);
return this;
}

public void RegisterSingleton(Type from, Type to)
public IContainerRegistry RegisterSingleton(Type from, Type to)
{
Instance.RegisterSingleton(from, to);
return this;
}

public void RegisterSingleton(Type from, Type to, string name)
public IContainerRegistry RegisterSingleton(Type from, Type to, string name)
{
Instance.RegisterSingleton(from, to, name);
return this;
}

public void Register(Type from, Type to)
public IContainerRegistry Register(Type from, Type to)
{
Instance.RegisterType(from, to);
return this;
}

public void Register(Type from, Type to, string name)
public IContainerRegistry Register(Type from, Type to, string name)
{
Instance.RegisterType(from, to, name);
return this;
}

public object Resolve(Type type)
Expand Down
12 changes: 6 additions & 6 deletions Source/Wpf/Prism.Wpf.Tests/Mocks/MockContainerAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@ public bool IsRegistered(Type type, string name)
throw new NotImplementedException();
}

public void Register(Type from, Type to)
public IContainerRegistry Register(Type from, Type to)
{
throw new NotImplementedException();
}

public void Register(Type from, Type to, string name)
public IContainerRegistry Register(Type from, Type to, string name)
{
throw new NotImplementedException();
}

public void RegisterInstance(Type type, object instance)
public IContainerRegistry RegisterInstance(Type type, object instance)
{
throw new NotImplementedException();
}

public void RegisterInstance(Type type, object instance, string name)
public IContainerRegistry RegisterInstance(Type type, object instance, string name)
{
throw new NotImplementedException();
}

public void RegisterSingleton(Type from, Type to)
public IContainerRegistry RegisterSingleton(Type from, Type to)
{
throw new NotImplementedException();
}

public void RegisterSingleton(Type from, Type to, string name)
public IContainerRegistry RegisterSingleton(Type from, Type to, string name)
{
throw new NotImplementedException();
}
Expand Down