Changed from Resolver to StaticResolver due to System.Resolver internal class conflict.
This commit is contained in:
Родитель
96e4b3bdff
Коммит
c7dc5c4575
|
@ -9,16 +9,26 @@ using DryIoc;
|
|||
|
||||
namespace Microsoft.AnyContainer.DryIoc
|
||||
{
|
||||
public class DryIocAnyContainer : AnyContainerBase
|
||||
/// <summary>
|
||||
/// DryIoc implementation of the abstract container.
|
||||
/// </summary>
|
||||
public class DryIocAnyContainer : AnyContainerBase
|
||||
{
|
||||
private readonly Container container;
|
||||
|
||||
public DryIocAnyContainer()
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="DryIocAnyContainer"/> class.
|
||||
/// </summary>
|
||||
public DryIocAnyContainer()
|
||||
{
|
||||
this.container = new Container();
|
||||
this.AddCoreScopes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="DryIocAnyContainer"/> class.
|
||||
/// </summary>
|
||||
/// <param name="container">The DryIoc container to power the class.</param>
|
||||
public DryIocAnyContainer(Container container)
|
||||
{
|
||||
this.container = container;
|
||||
|
@ -34,22 +44,42 @@ namespace Microsoft.AnyContainer.DryIoc
|
|||
this.AddScope(Lifetime.Transient, new DryIocTransientScopeRegistrar(this.container));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves an instance of the given type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to resolve.</typeparam>
|
||||
/// <returns>An instance of the given type.</returns>
|
||||
public override T Resolve<T>()
|
||||
{
|
||||
return this.container.Resolve<T>();
|
||||
}
|
||||
|
||||
public override object Resolve(Type componentType)
|
||||
/// <summary>
|
||||
/// Resolves an instance of the given type.
|
||||
/// </summary>
|
||||
/// <param name="componentType">The type to resolve.</param>
|
||||
/// <returns>An instance of the given type.</returns>
|
||||
public override object Resolve(Type componentType)
|
||||
{
|
||||
return this.container.Resolve(componentType);
|
||||
}
|
||||
|
||||
public override IList<T> ResolveAll<T>()
|
||||
/// <summary>
|
||||
/// Resolves all instances of the given type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to resolve.</typeparam>
|
||||
/// <returns>All instances of the given type.</returns>
|
||||
public override IList<T> ResolveAll<T>()
|
||||
{
|
||||
return this.container.ResolveMany<T>().ToList();
|
||||
}
|
||||
|
||||
public override IList<object> ResolveAll(Type componentType)
|
||||
/// <summary>
|
||||
/// Resolves all instances of the given type.
|
||||
/// </summary>
|
||||
/// <param name="componentType">The type to resolve.</param>
|
||||
/// <returns>All instances of the given type.</returns>
|
||||
public override IList<object> ResolveAll(Type componentType)
|
||||
{
|
||||
return this.container.ResolveMany(componentType).ToList();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,10 @@ using DryIoc;
|
|||
|
||||
namespace Microsoft.AnyContainer.DryIoc
|
||||
{
|
||||
public class DryIocSingletonScopeRegistrar : ScopeRegistrar
|
||||
/// <summary>
|
||||
/// Register items in the singleton scope for DryIoc.
|
||||
/// </summary>
|
||||
public class DryIocSingletonScopeRegistrar : ScopeRegistrar
|
||||
{
|
||||
private readonly Container container;
|
||||
|
||||
|
@ -18,19 +21,43 @@ namespace Microsoft.AnyContainer.DryIoc
|
|||
this.container = container;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers a type with a given implementation type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TRegisteredAs">The type to register.</typeparam>
|
||||
/// <typeparam name="TResolvedTo">The type to implement the registration.</typeparam>
|
||||
public override void Register<TRegisteredAs, TResolvedTo>()
|
||||
{
|
||||
this.container.Register<TRegisteredAs, TResolvedTo>(Reuse.Singleton);
|
||||
}
|
||||
|
||||
public override void Register(Type registeredAs, Type resolvedTo)
|
||||
/// <summary>
|
||||
/// Registers a type with a given implementation type.
|
||||
/// </summary>
|
||||
/// <param name="registeredAs">The type to register.</param>
|
||||
/// <param name="resolvedTo">The type to implement the registration.</param>
|
||||
public override void Register(Type registeredAs, Type resolvedTo)
|
||||
{
|
||||
this.container.Register(registeredAs, resolvedTo, Reuse.Singleton);
|
||||
}
|
||||
|
||||
public override void Register<T>(Func<T> factory)
|
||||
/// <summary>
|
||||
/// Registers a type with a given factory.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to register.</typeparam>
|
||||
/// <param name="factory">The factory to create the type.</param>
|
||||
public override void Register<T>(Func<T> factory)
|
||||
{
|
||||
this.container.RegisterDelegate(c => factory(), Reuse.Singleton);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers a type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to register.</typeparam>
|
||||
public override void Register<T>()
|
||||
{
|
||||
this.container.Register<T>(Reuse.Singleton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,10 @@ using DryIoc;
|
|||
|
||||
namespace Microsoft.AnyContainer.DryIoc
|
||||
{
|
||||
public class DryIocTransientScopeRegistrar : ScopeRegistrar
|
||||
/// <summary>
|
||||
/// Register items in the transient scope for DryIoc.
|
||||
/// </summary>
|
||||
public class DryIocTransientScopeRegistrar : ScopeRegistrar
|
||||
{
|
||||
private readonly Container container;
|
||||
|
||||
|
@ -18,19 +21,43 @@ namespace Microsoft.AnyContainer.DryIoc
|
|||
this.container = container;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers a type with a given implementation type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TRegisteredAs">The type to register.</typeparam>
|
||||
/// <typeparam name="TResolvedTo">The type to implement the registration.</typeparam>
|
||||
public override void Register<TRegisteredAs, TResolvedTo>()
|
||||
{
|
||||
this.container.Register<TRegisteredAs, TResolvedTo>(Reuse.Transient);
|
||||
}
|
||||
|
||||
public override void Register(Type registeredAs, Type resolvedTo)
|
||||
/// <summary>
|
||||
/// Registers a type with a given implementation type.
|
||||
/// </summary>
|
||||
/// <param name="registeredAs">The type to register.</param>
|
||||
/// <param name="resolvedTo">The type to implement the registration.</param>
|
||||
public override void Register(Type registeredAs, Type resolvedTo)
|
||||
{
|
||||
this.container.Register(registeredAs, resolvedTo, Reuse.Transient);
|
||||
}
|
||||
|
||||
public override void Register<T>(Func<T> factory)
|
||||
/// <summary>
|
||||
/// Registers a type with a given factory.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to register.</typeparam>
|
||||
/// <param name="factory">The factory to create the type.</param>
|
||||
public override void Register<T>(Func<T> factory)
|
||||
{
|
||||
this.container.RegisterDelegate(c => factory(), Reuse.Transient);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers a type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to register.</typeparam>
|
||||
public override void Register<T>()
|
||||
{
|
||||
this.container.Register<T>(Reuse.Transient);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace Microsoft.AnyContainer
|
|||
/// <summary>
|
||||
/// Resolves instances of types.
|
||||
/// </summary>
|
||||
public static class Resolver
|
||||
public static class StaticResolver
|
||||
{
|
||||
/// <summary>The current resolver implementation.</summary>
|
||||
private static IResolver currentResolver;
|
|
@ -90,9 +90,9 @@ namespace Microsoft.AnyContainer.UnitTests
|
|||
private static void TestTryResolveFail(Func<AnyContainerBase> factory)
|
||||
{
|
||||
AnyContainerBase container = factory();
|
||||
Resolver.SetResolver(container);
|
||||
StaticResolver.SetResolver(container);
|
||||
|
||||
ILogger logger = Resolver.TryResolve<ILogger>();
|
||||
ILogger logger = StaticResolver.TryResolve<ILogger>();
|
||||
|
||||
Assert.IsNull(logger);
|
||||
}
|
||||
|
@ -102,9 +102,9 @@ namespace Microsoft.AnyContainer.UnitTests
|
|||
AnyContainerBase container = factory();
|
||||
container.RegisterSingleton<ILogger, Logger>();
|
||||
|
||||
Resolver.SetResolver(container);
|
||||
StaticResolver.SetResolver(container);
|
||||
|
||||
ILogger logger = Resolver.TryResolve<ILogger>();
|
||||
ILogger logger = StaticResolver.TryResolve<ILogger>();
|
||||
|
||||
Assert.IsNotNull(logger);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче