Skip to content

Commit 8445c14

Browse files
authored
Merge pull request #32 from ENikS/master
Fixing 6, 29, 30
2 parents 8c6ed5c + a4e11da commit 8445c14

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

src/Builder/IBuilderContext.cs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,15 @@ public interface IBuilderContext
9999
object CurrentOperation { get; set; }
100100

101101
/// <summary>
102-
/// The build context used to resolve a dependency during the build operation represented by this context.
102+
/// The child build context.
103103
/// </summary>
104104
IBuilderContext ChildContext { get; }
105105

106+
/// <summary>
107+
/// The parent build context.
108+
/// </summary>
109+
IBuilderContext ParentContext { get; }
110+
106111
/// <summary>
107112
/// Add a new set of resolver override objects to the current build operation.
108113
/// </summary>
@@ -118,16 +123,15 @@ public interface IBuilderContext
118123
IDependencyResolverPolicy GetOverriddenResolver(Type dependencyType);
119124

120125
/// <summary>
121-
/// A convenience method to do a new buildup operation on an existing context. This
122-
/// overload allows you to specify extra policies which will be in effect for the duration
123-
/// of the build.
126+
/// A method to do a new buildup operation on an existing context.
124127
/// </summary>
125-
/// <param name="newBuildKey">Key defining what to build up.</param>
128+
/// <param name="type">Type of to build</param>
129+
/// <param name="name">Name of the type to build</param>
126130
/// <param name="childCustomizationBlock">A delegate that takes a <see cref="IBuilderContext"/>. This
127131
/// is invoked with the new child context before the build up process starts. This gives callers
128132
/// the opportunity to customize the context for the build process.</param>
129-
/// <returns>Created object.</returns>
130-
object NewBuildUp(INamedType newBuildKey, Action<IBuilderContext> childCustomizationBlock = null);
133+
/// <returns>Resolved object</returns>
134+
object NewBuildUp(Type type, string name, Action<IBuilderContext> childCustomizationBlock = null);
131135
}
132136

133137
/// <summary>
@@ -136,6 +140,24 @@ public interface IBuilderContext
136140
/// </summary>
137141
public static class BuilderContextExtensions
138142
{
143+
144+
/// <summary>
145+
/// A convenience method to do a new buildup operation on an existing context. This
146+
/// overload allows you to specify extra policies which will be in effect for the duration
147+
/// of the build.
148+
/// </summary>
149+
/// <param name="newBuildKey">Key defining what to build up.</param>
150+
/// <param name="childCustomizationBlock">A delegate that takes a <see cref="IBuilderContext"/>. This
151+
/// is invoked with the new child context before the build up process starts. This gives callers
152+
/// the opportunity to customize the context for the build process.</param>
153+
/// <returns>Created object.</returns>
154+
public static object NewBuildUp(this IBuilderContext context, INamedType newBuildKey, Action<IBuilderContext> childCustomizationBlock = null)
155+
{
156+
return (context ?? throw new ArgumentNullException(nameof(context)))
157+
.NewBuildUp(newBuildKey?.Type, newBuildKey?.Name, childCustomizationBlock);
158+
}
159+
160+
139161
/// <summary>
140162
/// Start a recursive build up operation to retrieve the default
141163
/// value for the given <typeparamref name="TResult"/> type.
@@ -145,7 +167,8 @@ public static class BuilderContextExtensions
145167
/// <returns>Resulting object.</returns>
146168
public static TResult NewBuildUp<TResult>(this IBuilderContext context)
147169
{
148-
return context.NewBuildUp<TResult>(null);
170+
return (TResult)(context ?? throw new ArgumentNullException(nameof(context)))
171+
.NewBuildUp(typeof(TResult), null, null);
149172
}
150173

151174
/// <summary>
@@ -159,7 +182,7 @@ public static TResult NewBuildUp<TResult>(this IBuilderContext context)
159182
public static TResult NewBuildUp<TResult>(this IBuilderContext context, string name)
160183
{
161184
return (TResult)(context ?? throw new ArgumentNullException(nameof(context)))
162-
.NewBuildUp(NamedTypeBuildKey.Make<TResult>(name));
185+
.NewBuildUp(typeof(TResult), name, null);
163186
}
164187

165188
/// <summary>

src/IUnityContainer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ public interface IUnityContainer : IDisposable
123123
/// <returns>The new child container.</returns>
124124
IUnityContainer CreateChildContainer();
125125

126+
// TODO: Add summary
127+
bool IsRegistered(Type type, string name);
128+
126129
/// <summary>
127130
/// GetOrDefault a sequence of <see cref="IContainerRegistration"/> that describe the current state
128131
/// of the container.

src/Utility/UnityContainerExtensions.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ public static TConfigurator Configure<TConfigurator>(this IUnityContainer contai
788788

789789
#endregion
790790

791-
#region Introspection Helpers
791+
#region Registration Helpers
792792

793793
/// <summary>
794794
/// Check if a particular type has been registered with the container with
@@ -803,21 +803,6 @@ public static bool IsRegistered(this IUnityContainer container, Type typeToCheck
803803
.IsRegistered(typeToCheck ?? throw new ArgumentNullException(nameof(typeToCheck)), null);
804804
}
805805

806-
/// <summary>
807-
/// Check if a particular type/name pair has been registered with the container.
808-
/// </summary>
809-
/// <param name="container">Container to inspect.</param>
810-
/// <param name="typeToCheck">Type to check registration for.</param>
811-
/// <param name="nameToCheck">Name to check registration for.</param>
812-
/// <returns>True if this type/name pair has been registered, false if not.</returns>
813-
public static bool IsRegistered(this IUnityContainer container, Type typeToCheck, string nameToCheck)
814-
{
815-
var registration = from r in (container ?? throw new ArgumentNullException(nameof(container))).Registrations
816-
where r.RegisteredType == (typeToCheck ?? throw new ArgumentNullException(nameof(typeToCheck))) && r.Name == nameToCheck
817-
select r;
818-
return registration.FirstOrDefault() != null;
819-
}
820-
821806
/// <summary>
822807
/// Check if a particular type has been registered with the container with the default name.
823808
/// </summary>
@@ -826,7 +811,7 @@ public static bool IsRegistered(this IUnityContainer container, Type typeToCheck
826811
/// <returns>True if this type has been registered, false if not.</returns>
827812
public static bool IsRegistered<T>(this IUnityContainer container)
828813
{
829-
return (container ?? throw new ArgumentNullException(nameof(container))).IsRegistered(typeof(T));
814+
return (container ?? throw new ArgumentNullException(nameof(container))).IsRegistered(typeof(T), null);
830815
}
831816

832817
/// <summary>

0 commit comments

Comments
 (0)