- 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. 6
      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>
/// Internal method used by the factory source generator to add the generated factory to the registration
/// </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>
void AddGeneratedFactory<TFactory>(TFactory generatedFactory);
void AddGeneratedFactory<TFactory>(IFactoryBuilder factoryBuilder);
}
internal interface IWithFactoryInternal : IWithFactory

@ -486,6 +486,19 @@
<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>
</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">
<summary>
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>
<returns>The current instance of this <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistrationBase"/></returns>
</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>
Internal method used by the factory source generator to add the generated factory to the registration
</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>
</member>
<member name="P:LightweightIocContainer.Interfaces.Registrations.Fluent.IWithFactoryInternal.Factory">
@ -1608,11 +1621,11 @@
<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>
</member>
<member name="M:LightweightIocContainer.Registrations.RegistrationBase.AddGeneratedFactory``1(``0)">
<member name="M:LightweightIocContainer.Registrations.RegistrationBase.AddGeneratedFactory``1(LightweightIocContainer.Interfaces.Factories.IFactoryBuilder)">
<summary>
Internal method used by the factory source generator to add the generated factory to the registration
</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>
</member>
<member name="M:LightweightIocContainer.Registrations.RegistrationBase.WithFactory``2">

@ -124,11 +124,11 @@ internal abstract class RegistrationBase : IRegistrationBase, IWithFactoryIntern
/// <summary>
/// Internal method used by the factory source generator to add the generated factory to the registration
/// </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>
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;
_container.RegisterFactory(factory);

Loading…
Cancel
Save