Skip to content

Commit 1cade71

Browse files
committed
Fixes #12
Fixes #10
1 parent 6565b23 commit 1cade71

File tree

6 files changed

+65
-66
lines changed

6 files changed

+65
-66
lines changed

src/Builder/Strategy/BuilderStrategy.cs

-20
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,5 @@ public virtual void PreBuildUp(IBuilderContext context)
2727
public virtual void PostBuildUp(IBuilderContext context)
2828
{
2929
}
30-
31-
/// <summary>
32-
/// Called during the chain of responsibility for a teardown operation. The
33-
/// PreTearDown method is called when the chain is being executed in the
34-
/// forward direction.
35-
/// </summary>
36-
/// <param name="context">Context of the teardown operation.</param>
37-
public virtual void PreTearDown(IBuilderContext context)
38-
{
39-
}
40-
41-
/// <summary>
42-
/// Called during the chain of responsibility for a teardown operation. The
43-
/// PostTearDown method is called when the chain has finished the PreTearDown
44-
/// phase and executes in reverse order from the PreTearDown calls.
45-
/// </summary>
46-
/// <param name="context">Context of the teardown operation.</param>
47-
public virtual void PostTearDown(IBuilderContext context)
48-
{
49-
}
5030
}
5131
}

src/Builder/Strategy/IBuilderStrategy.cs

-16
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,5 @@ public interface IBuilderStrategy
2424
/// </summary>
2525
/// <param name="context">Context of the build operation.</param>
2626
void PostBuildUp(IBuilderContext context);
27-
28-
/// <summary>
29-
/// Called during the chain of responsibility for a teardown operation. The
30-
/// PreTearDown method is called when the chain is being executed in the
31-
/// forward direction.
32-
/// </summary>
33-
/// <param name="context">Context of the teardown operation.</param>
34-
void PreTearDown(IBuilderContext context);
35-
36-
/// <summary>
37-
/// Called during the chain of responsibility for a teardown operation. The
38-
/// PostTearDown method is called when the chain has finished the PreTearDown
39-
/// phase and executes in reverse order from the PreTearDown calls.
40-
/// </summary>
41-
/// <param name="context">Context of the teardown operation.</param>
42-
void PostTearDown(IBuilderContext context);
4327
}
4428
}
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Unity.Lifetime;
4+
using Unity.Registration;
5+
6+
namespace Unity.Builder.Strategy
7+
{
8+
public interface IRegisterStrategy
9+
{
10+
/// <summary>
11+
/// Register a type mapping with the container, where the created instances will use
12+
/// the given <see cref="LifetimeManager"/>.
13+
/// </summary>
14+
/// <param name="typeFrom"><see cref="Type"/> that will be requested.</param>
15+
/// <param name="typeTo"><see cref="Type"/> that will actually be returned.</param>
16+
/// <param name="name">Name to use for registration, null if a default registration.</param>
17+
/// <param name="lifetimeManager">The <see cref="LifetimeManager"/> that controls the lifetime
18+
/// of the returned instance.</param>
19+
/// <param name="injectionMembers">Injection configuration objects. Can be null.</param>
20+
/// <returns>List of policies this registration generates.</returns>
21+
IEnumerable<IBuilderPolicy> RegisterType(Type typeFrom, Type typeTo, string name, LifetimeManager lifetimeManager, params InjectionMember[] injectionMembers);
22+
23+
/// <summary>
24+
/// Register an instance with the container.
25+
/// </summary>
26+
/// <remarks>
27+
/// <para>
28+
/// Instance registration is much like setting a type as a singleton, except that instead
29+
/// of the container creating the instance the first time it is requested, the user
30+
/// creates the instance ahead of type and adds that instance to the container.
31+
/// </para>
32+
/// </remarks>
33+
/// <param name="type">Type of instance to register (may be an implemented interface instead of the full type).</param>
34+
/// <param name="instance">Object to returned.</param>
35+
/// <param name="name">Name for registration.</param>
36+
/// <param name="lifetime">
37+
/// <see cref="LifetimeManager"/> object that controls how this instance will be managed by the container.</param>
38+
/// <returns>List of policies this registration generates.</returns>
39+
IEnumerable<IBuilderPolicy> RegisterInstance(Type type, string name, object instance, LifetimeManager lifetime);
40+
41+
}
42+
}

src/IUnityContainer.cs

-23
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,6 @@ public interface IUnityContainer : IDisposable
5454
/// <returns>The retrieved object.</returns>
5555
object Resolve(Type type, string name, params ResolverOverride[] resolverOverrides);
5656

57-
/// <summary>
58-
/// Return instances of all registered types requested.
59-
/// </summary>
60-
/// <remarks>
61-
/// <para>
62-
/// This method is useful if you've registered multiple types with the same
63-
/// <see cref="Type"/> but different names.
64-
/// </para>
65-
/// <para>
66-
/// Be aware that this method does NOT return an instance for the default (unnamed) registration.
67-
/// </para>
68-
/// </remarks>
69-
/// <param name="type">The type requested.</param>
70-
/// <param name="resolverOverrides">Any overrides for the resolve calls.</param>
71-
/// <returns>Set of objects of type <paramref name="type"/>.</returns>
72-
IEnumerable<object> ResolveAll(Type type, params ResolverOverride[] resolverOverrides);
73-
7457
/// <summary>
7558
/// Run an existing object through the container and perform injection on it.
7659
/// </summary>
@@ -89,12 +72,6 @@ public interface IUnityContainer : IDisposable
8972
/// cause this to return a different object (but still type compatible with <paramref name="type"/>).</returns>
9073
object BuildUp(Type type, object existing, string name, params ResolverOverride[] resolverOverrides);
9174

92-
/// <summary>
93-
/// Run an existing object through the container, and clean it up.
94-
/// </summary>
95-
/// <param name="o">The object to tear down.</param>
96-
void Teardown(object o);
97-
9875
/// <summary>
9976
/// Add an extension object to the container.
10077
/// </summary>

src/Strategy/IStrategyChain.cs

-7
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,5 @@ public interface IStrategyChain : IEnumerable<IBuilderStrategy>
1818
/// <param name="context">Context for the build process.</param>
1919
/// <returns>The build up object</returns>
2020
object ExecuteBuildUp(IBuilderContext context);
21-
22-
/// <summary>
23-
/// Execute this strategy chain against the given context,
24-
/// calling the TearDown methods on the strategies.
25-
/// </summary>
26-
/// <param name="context">Context for the teardown process.</param>
27-
void ExecuteTearDown(IBuilderContext context);
2821
}
2922
}

src/Utility/UnityContainerExtensions.cs

+23
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,29 @@ public static object Resolve(this IUnityContainer container, Type t, params Reso
488488
return (container ?? throw new ArgumentNullException(nameof(container))).Resolve(t, null, overrides);
489489
}
490490

491+
492+
/// <summary>
493+
/// Return instances of all registered types requested.
494+
/// </summary>
495+
/// <remarks>
496+
/// <para>
497+
/// This method is useful if you've registered multiple types with the same
498+
/// <see cref="Type"/> but different names.
499+
/// </para>
500+
/// <para>
501+
/// Be aware that this method does NOT return an instance for the default (unnamed) registration.
502+
/// </para>
503+
/// </remarks>
504+
/// <param name="container">Container to resolve from.</param>
505+
/// <param name="type">The type requested.</param>
506+
/// <param name="resolverOverrides">Any overrides for the resolve calls.</param>
507+
/// <returns>Set of objects of type <paramref name="type"/>.</returns>
508+
public static IEnumerable<object> ResolveAll(this IUnityContainer container, Type type, params ResolverOverride[] resolverOverrides)
509+
{
510+
var result = container.Resolve((type ?? throw new ArgumentNullException(nameof(type))).MakeArrayType(), resolverOverrides);
511+
return result is IEnumerable<object> objects ? objects : ((Array)result).Cast<object>();
512+
}
513+
491514
#endregion
492515

493516
#region ResolveAll overloads

0 commit comments

Comments
 (0)