1313
1414namespace UnityContainerAttributeRegistration . Populator
1515{
16+ /// <summary>
17+ /// Populator for the <see cref="UnityContainerAttributeRegistration.Attribute.RegisterFactoryAttribute" />.
18+ /// </summary>
1619 internal class FactoryPopulator : Populator
1720 {
21+ /// <inheritdoc cref="Populator.Populate" />
22+ /// <exception cref="InvalidOperationException">Invalid factory method.</exception>
1823 public override IUnityContainer Populate ( IUnityContainer container , IList < Type > typesWithAttribute )
1924 {
2025 IEnumerable < FactoryToRegister > factoriesToRegister =
21- typesWithAttribute . SelectMany ( providerClassType => GetInstancesToRegisterFor ( container , providerClassType ) ) ;
26+ typesWithAttribute . SelectMany ( providerClassType => GetFactoryToRegisterFor ( container , providerClassType ) ) ;
2227
2328 foreach ( FactoryToRegister factoryToRegister in factoriesToRegister )
2429 {
@@ -32,7 +37,14 @@ public override IUnityContainer Populate(IUnityContainer container, IList<Type>
3237 return container ;
3338 }
3439
35- private IEnumerable < FactoryToRegister > GetInstancesToRegisterFor ( IUnityContainer container , Type providerClassType )
40+ /// <summary>
41+ /// Get all candidates to register.
42+ /// </summary>
43+ /// <param name="container"><see cref="IUnityContainer" /> to instantiate the provider class</param>
44+ /// <param name="providerClassType">Factory provider class</param>
45+ /// <returns>List of candidates to register</returns>
46+ /// <exception cref="InvalidOperationException">Invalid factory method.</exception>
47+ private IEnumerable < FactoryToRegister > GetFactoryToRegisterFor ( IUnityContainer container , Type providerClassType )
3648 {
3749 object providerClassInstance = container . Resolve ( providerClassType ) ;
3850 MethodInfo [ ] methodInfos = providerClassType . GetMethods ( ) ;
@@ -43,6 +55,13 @@ private IEnumerable<FactoryToRegister> GetInstancesToRegisterFor(IUnityContainer
4355 . ToList ( ) ;
4456 }
4557
58+ /// <summary>
59+ /// Transform a <see cref="MethodInfo" /> and an instance to a <see cref="FactoryToRegister" /> object.
60+ /// </summary>
61+ /// <param name="info"><see cref="MethodInfo" /> of the factory method.</param>
62+ /// <param name="instance">Instance of the factory method.</param>
63+ /// <returns>Wrapper for easy registration.</returns>
64+ /// <exception cref="InvalidOperationException">Invalid factory method.</exception>
4665 private FactoryToRegister CreateFactoryToRegisterFrom ( MethodInfo info , object instance )
4766 {
4867 RegisterFactoryAttribute attribute = info . GetCustomAttribute < RegisterFactoryAttribute > ( ) ;
@@ -66,6 +85,11 @@ private FactoryToRegister CreateFactoryToRegisterFrom(MethodInfo info, object in
6685 return new FactoryToRegister ( returnType , GetFactoryMethodFor ( info , instance ) , lifetimeManager ) ;
6786 }
6887
88+ /// <summary>
89+ /// Verify that the parameters matches the requirements of Unity
90+ /// </summary>
91+ /// <param name="methodInfo"><see cref="MethodInfo" /> to check.</param>
92+ /// <returns>Whether <paramref name="methodInfo" /> matches the requirements or not.</returns>
6993 private bool IsUnityFactorySignature ( MethodInfo methodInfo )
7094 {
7195 ParameterInfo [ ] parameters = methodInfo . GetParameters ( ) ;
@@ -88,6 +112,12 @@ private bool IsUnityFactorySignature(MethodInfo methodInfo)
88112 }
89113 }
90114
115+ /// <summary>
116+ /// Create a wrapper function for a factory method.
117+ /// </summary>
118+ /// <param name="methodInfo"><see cref="MethodInfo" /> of the factory method.</param>
119+ /// <param name="instance">Instance of the factory method.</param>
120+ /// <returns><see cref="Func{TResult}" /> to call the factory method.</returns>
91121 private Func < IUnityContainer , Type , string , object > GetFactoryMethodFor ( MethodInfo methodInfo , object instance )
92122 {
93123 return ( container , typeValue , stringValue ) =>
@@ -105,6 +135,9 @@ private Func<IUnityContainer, Type, string, object> GetFactoryMethodFor(MethodIn
105135 } ;
106136 }
107137
138+ /// <summary>
139+ /// Wrapper to register factories
140+ /// </summary>
108141 private sealed class FactoryToRegister
109142 {
110143 public FactoryToRegister ( [ NotNull ] Type returnType ,
@@ -116,12 +149,21 @@ public FactoryToRegister([NotNull] Type
116149 LifetimeManager = lifetimeManager ;
117150 }
118151
152+ /// <summary>
153+ /// Requested type as return type of the factory
154+ /// </summary>
119155 [ NotNull ]
120156 public Type ReturnType { get ; }
121157
158+ /// <summary>
159+ /// Factory method
160+ /// </summary>
122161 [ NotNull ]
123162 public Func < IUnityContainer , Type , string , object > Factory { get ; }
124163
164+ /// <summary>
165+ /// Used lifetime manager
166+ /// </summary>
125167 [ CanBeNull ]
126168 public IFactoryLifetimeManager LifetimeManager { get ; }
127169 }
0 commit comments