- introduce factory builder to create factory instances

pull/62/head
Simon G. 4 days ago
parent be1cea11e0
commit daad788b2e
Signed by: SimonG
GPG Key ID: 0B82B964BA536523
  1. 19
      LightweightIocContainer/Interfaces/Factories/IFactoryBuilder.cs
  2. 4
      LightweightIocContainer/Interfaces/Registrations/Fluent/IWithFactory.cs
  3. 21
      LightweightIocContainer/LightweightIocContainer.xml
  4. 8
      LightweightIocContainer/Registrations/RegistrationBase.cs

@ -0,0 +1,19 @@
// Author: Simon.Gockner
// Created: 2025-12-02
// Copyright(c) 2025 SimonG. All Rights Reserved.
namespace LightweightIocContainer.Interfaces.Factories;
/// <summary>
/// Internal class used by the factory source generator to create factory instances
/// </summary>
public interface IFactoryBuilder
{
/// <summary>
/// Internal method used by the factory source generator to create factory instances
/// </summary>
/// <param name="container">The current instance of the <see cref="IocContainer"/></param>
/// <typeparam name="TFactory">The type of the factory</typeparam>
/// <returns>The created factory instance</returns>
TFactory Create<TFactory>(IocContainer container);
}

@ -29,9 +29,9 @@ public interface IWithFactory
/// <summary> /// <summary>
/// Internal method used by the factory source generator to add the generated factory to the registration /// Internal method used by the factory source generator to add the generated factory to the registration
/// </summary> /// </summary>
/// <param name="generatedFactory">The actual generated factory</param> /// <param name="factoryBuilder">The factory creator</param>
/// <typeparam name="TFactory">The type of the generated factory</typeparam> /// <typeparam name="TFactory">The type of the generated factory</typeparam>
void AddGeneratedFactory<TFactory>(TFactory generatedFactory); void AddGeneratedFactory<TFactory>(IFactoryBuilder factoryBuilder);
} }
internal interface IWithFactoryInternal : IWithFactory internal interface IWithFactoryInternal : IWithFactory

@ -486,6 +486,19 @@
<param name="assembly">The given <see cref="T:System.Reflection.Assembly"/></param> <param name="assembly">The given <see cref="T:System.Reflection.Assembly"/></param>
<returns>A new <see cref="T:LightweightIocContainer.Interfaces.Installers.IAssemblyInstaller"/> with the given <see cref="T:System.Reflection.Assembly"/></returns> <returns>A new <see cref="T:LightweightIocContainer.Interfaces.Installers.IAssemblyInstaller"/> with the given <see cref="T:System.Reflection.Assembly"/></returns>
</member> </member>
<member name="T:LightweightIocContainer.Interfaces.Factories.IFactoryBuilder">
<summary>
Internal class used by the factory source generator to create factory instances
</summary>
</member>
<member name="M:LightweightIocContainer.Interfaces.Factories.IFactoryBuilder.Create``1(LightweightIocContainer.IocContainer)">
<summary>
Internal method used by the factory source generator to create factory instances
</summary>
<param name="container">The current instance of the <see cref="T:LightweightIocContainer.IocContainer"/></param>
<typeparam name="TFactory">The type of the factory</typeparam>
<returns>The created factory instance</returns>
</member>
<member name="T:LightweightIocContainer.Interfaces.Factories.ITypedFactory"> <member name="T:LightweightIocContainer.Interfaces.Factories.ITypedFactory">
<summary> <summary>
Non-generic <see cref="T:LightweightIocContainer.Interfaces.Factories.ITypedFactory`1"/> Non-generic <see cref="T:LightweightIocContainer.Interfaces.Factories.ITypedFactory`1"/>
@ -670,11 +683,11 @@
<typeparam name="TFactoryImplementation">The type of the implementation for the custom factory</typeparam> <typeparam name="TFactoryImplementation">The type of the implementation for the custom factory</typeparam>
<returns>The current instance of this <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistrationBase"/></returns> <returns>The current instance of this <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistrationBase"/></returns>
</member> </member>
<member name="M:LightweightIocContainer.Interfaces.Registrations.Fluent.IWithFactory.AddGeneratedFactory``1(``0)"> <member name="M:LightweightIocContainer.Interfaces.Registrations.Fluent.IWithFactory.AddGeneratedFactory``1(LightweightIocContainer.Interfaces.Factories.IFactoryBuilder)">
<summary> <summary>
Internal method used by the factory source generator to add the generated factory to the registration Internal method used by the factory source generator to add the generated factory to the registration
</summary> </summary>
<param name="generatedFactory">The actual generated factory</param> <param name="factoryBuilder">The factory creator</param>
<typeparam name="TFactory">The type of the generated factory</typeparam> <typeparam name="TFactory">The type of the generated factory</typeparam>
</member> </member>
<member name="P:LightweightIocContainer.Interfaces.Registrations.Fluent.IWithFactoryInternal.Factory"> <member name="P:LightweightIocContainer.Interfaces.Registrations.Fluent.IWithFactoryInternal.Factory">
@ -1608,11 +1621,11 @@
<typeparam name="TFactory">The type of the abstract typed factory</typeparam> <typeparam name="TFactory">The type of the abstract typed factory</typeparam>
<returns>The current instance of this <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistrationBase"/></returns> <returns>The current instance of this <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistrationBase"/></returns>
</member> </member>
<member name="M:LightweightIocContainer.Registrations.RegistrationBase.AddGeneratedFactory``1(``0)"> <member name="M:LightweightIocContainer.Registrations.RegistrationBase.AddGeneratedFactory``1(LightweightIocContainer.Interfaces.Factories.IFactoryBuilder)">
<summary> <summary>
Internal method used by the factory source generator to add the generated factory to the registration Internal method used by the factory source generator to add the generated factory to the registration
</summary> </summary>
<param name="generatedFactory">The actual generated factory</param> <param name="factoryBuilder">The factory creator</param>
<typeparam name="TFactory">The type of the generated factory</typeparam> <typeparam name="TFactory">The type of the generated factory</typeparam>
</member> </member>
<member name="M:LightweightIocContainer.Registrations.RegistrationBase.WithFactory``2"> <member name="M:LightweightIocContainer.Registrations.RegistrationBase.WithFactory``2">

@ -120,15 +120,15 @@ internal abstract class RegistrationBase : IRegistrationBase, IWithFactoryIntern
return this; return this;
} }
/// <summary> /// <summary>
/// Internal method used by the factory source generator to add the generated factory to the registration /// Internal method used by the factory source generator to add the generated factory to the registration
/// </summary> /// </summary>
/// <param name="generatedFactory">The actual generated factory</param> /// <param name="factoryBuilder">The factory creator</param>
/// <typeparam name="TFactory">The type of the generated factory</typeparam> /// <typeparam name="TFactory">The type of the generated factory</typeparam>
public void AddGeneratedFactory<TFactory>(TFactory generatedFactory) public void AddGeneratedFactory<TFactory>(IFactoryBuilder factoryBuilder)
{ {
TypedFactory<TFactory> factory = new(generatedFactory); TypedFactory<TFactory> factory = new(factoryBuilder.Create<TFactory>(_container));
Factory = factory; Factory = factory;
_container.RegisterFactory(factory); _container.RegisterFactory(factory);

Loading…
Cancel
Save