Compare commits

..

5 Commits

  1. 1
      LightweightIocContainer.Validation/LightweightIocContainer.Validation.csproj
  2. 1
      LightweightIocContainer/LightweightIocContainer.csproj
  3. 25
      LightweightIocContainer/LightweightIocContainer.xml
  4. 45
      LightweightIocContainer/Registrations/MultipleRegistration.cs
  5. 2
      LightweightIocContainer/Registrations/RegistrationBase.cs
  6. 4
      README.md
  7. 19
      Test.LightweightIocContainer/DisposeStrategyTest.cs

@ -11,7 +11,6 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<DocumentationFile>LightweightIocContainer.Validation.xml</DocumentationFile> <DocumentationFile>LightweightIocContainer.Validation.xml</DocumentationFile>
<VersionPrefix>4.4.0</VersionPrefix> <VersionPrefix>4.4.0</VersionPrefix>
<VersionSuffix>beta7</VersionSuffix>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>

@ -11,7 +11,6 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<DocumentationFile>LightweightIocContainer.xml</DocumentationFile> <DocumentationFile>LightweightIocContainer.xml</DocumentationFile>
<VersionPrefix>4.4.0</VersionPrefix> <VersionPrefix>4.4.0</VersionPrefix>
<VersionSuffix>beta7</VersionSuffix>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>

@ -1344,6 +1344,31 @@
A <see cref="T:System.Collections.Generic.List`1"/> of <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/>s that are registered within this <see cref="T:LightweightIocContainer.Registrations.MultipleRegistration`2"/> A <see cref="T:System.Collections.Generic.List`1"/> of <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/>s that are registered within this <see cref="T:LightweightIocContainer.Registrations.MultipleRegistration`2"/>
</summary> </summary>
</member> </member>
<member name="M:LightweightIocContainer.Registrations.MultipleRegistration`2.WithParameters(System.Object[])">
<summary>
Pass parameters that will be used to <see cref="M:LightweightIocContainer.IocContainer.Resolve``1"/> an instance of this <see cref="P:LightweightIocContainer.Interfaces.Registrations.IRegistration.InterfaceType"/>
<para>Parameters set with this method are always inserted at the beginning of the argument list if more parameters are given when resolving</para>
</summary>
<param name="parameters">The parameters</param>
<returns>The current instance of this <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/></returns>
<exception cref="T:LightweightIocContainer.Exceptions.InvalidRegistrationException"><see cref="P:LightweightIocContainer.Registrations.RegistrationBase.Parameters"/> are already set or no parameters given</exception>
</member>
<member name="M:LightweightIocContainer.Registrations.MultipleRegistration`2.WithParameters(System.ValueTuple{System.Int32,System.Object}[])">
<summary>
Pass parameters that will be used to<see cref="M:LightweightIocContainer.IocContainer.Resolve``1"/> an instance of this <see cref="P:LightweightIocContainer.Interfaces.Registrations.IRegistration.InterfaceType"/>
<para>Parameters set with this method are inserted at the position in the argument list that is passed with the parameter if more parameters are given when resolving</para>
</summary>
<param name="parameters">The parameters with their position</param>
<returns>The current instance of this <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/></returns>
<exception cref="T:LightweightIocContainer.Exceptions.InvalidRegistrationException"><see cref="P:LightweightIocContainer.Registrations.RegistrationBase.Parameters"/> are already set or no parameters given</exception>
</member>
<member name="M:LightweightIocContainer.Registrations.MultipleRegistration`2.WithDisposeStrategy(LightweightIocContainer.DisposeStrategy)">
<summary>
Add a <see cref="T:LightweightIocContainer.DisposeStrategy"/> for the <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistrationBase"/>
</summary>
<param name="disposeStrategy">The <see cref="T:LightweightIocContainer.DisposeStrategy"/></param>
<returns>The current instance of this <see cref="T:LightweightIocContainer.Registrations.RegistrationBase"/></returns>
</member>
<member name="T:LightweightIocContainer.Registrations.MultipleRegistration`3"> <member name="T:LightweightIocContainer.Registrations.MultipleRegistration`3">
<summary> <summary>
An <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/> to register multiple interfaces for on implementation type An <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/> to register multiple interfaces for on implementation type

@ -2,8 +2,10 @@
// Created: 2019-12-07 // Created: 2019-12-07
// Copyright(c) 2019 SimonG. All Rights Reserved. // Copyright(c) 2019 SimonG. All Rights Reserved.
using LightweightIocContainer.Exceptions;
using LightweightIocContainer.Interfaces; using LightweightIocContainer.Interfaces;
using LightweightIocContainer.Interfaces.Registrations; using LightweightIocContainer.Interfaces.Registrations;
using LightweightIocContainer.Interfaces.Registrations.Fluent;
namespace LightweightIocContainer.Registrations; namespace LightweightIocContainer.Registrations;
@ -31,6 +33,49 @@ internal abstract class MultipleRegistration<TInterface1, TImplementation> : Typ
/// A <see cref="List{T}"/> of <see cref="IRegistration"/>s that are registered within this <see cref="MultipleRegistration{TInterface1,TInterface2}"/> /// A <see cref="List{T}"/> of <see cref="IRegistration"/>s that are registered within this <see cref="MultipleRegistration{TInterface1,TInterface2}"/>
/// </summary> /// </summary>
public List<IRegistration> Registrations { get; protected init; } = []; public List<IRegistration> Registrations { get; protected init; } = [];
/// <summary>
/// Pass parameters that will be used to <see cref="IocContainer.Resolve{T}()"/> an instance of this <see cref="IRegistration.InterfaceType"/>
/// <para>Parameters set with this method are always inserted at the beginning of the argument list if more parameters are given when resolving</para>
/// </summary>
/// <param name="parameters">The parameters</param>
/// <returns>The current instance of this <see cref="IRegistration"/></returns>
/// <exception cref="InvalidRegistrationException"><see cref="RegistrationBase.Parameters"/> are already set or no parameters given</exception>
public override IRegistrationBase WithParameters(params object[] parameters)
{
foreach (IWithParameters registration in Registrations.OfType<IWithParameters>())
registration.WithParameters(parameters);
return this;
}
/// <summary>
/// Pass parameters that will be used to<see cref="IocContainer.Resolve{T}()"/> an instance of this <see cref="IRegistration.InterfaceType"/>
/// <para>Parameters set with this method are inserted at the position in the argument list that is passed with the parameter if more parameters are given when resolving</para>
/// </summary>
/// <param name="parameters">The parameters with their position</param>
/// <returns>The current instance of this <see cref="IRegistration"/></returns>
/// <exception cref="InvalidRegistrationException"><see cref="RegistrationBase.Parameters"/> are already set or no parameters given</exception>
public override IRegistrationBase WithParameters(params (int index, object parameter)[] parameters)
{
foreach (IWithParameters registration in Registrations.OfType<IWithParameters>())
registration.WithParameters(parameters);
return this;
}
/// <summary>
/// Add a <see cref="DisposeStrategy"/> for the <see cref="IRegistrationBase"/>
/// </summary>
/// <param name="disposeStrategy">The <see cref="DisposeStrategy"/></param>
/// <returns>The current instance of this <see cref="RegistrationBase"/></returns>
public override IRegistrationBase WithDisposeStrategy(DisposeStrategy disposeStrategy)
{
foreach (IWithDisposeStrategy registration in Registrations.OfType<IWithDisposeStrategy>())
registration.WithDisposeStrategy(disposeStrategy);
return this;
}
} }
/// <summary> /// <summary>

@ -140,7 +140,7 @@ internal abstract class RegistrationBase : IRegistrationBase, IWithFactoryIntern
/// </summary> /// </summary>
/// <param name="disposeStrategy">The <see cref="DisposeStrategy"/></param> /// <param name="disposeStrategy">The <see cref="DisposeStrategy"/></param>
/// <returns>The current instance of this <see cref="RegistrationBase"/></returns> /// <returns>The current instance of this <see cref="RegistrationBase"/></returns>
public IRegistrationBase WithDisposeStrategy(DisposeStrategy disposeStrategy) public virtual IRegistrationBase WithDisposeStrategy(DisposeStrategy disposeStrategy)
{ {
DisposeStrategy = disposeStrategy; DisposeStrategy = disposeStrategy;
return this; return this;

@ -19,7 +19,7 @@ A lightweight IOC Container that is powerful enough to do all the things you nee
The easiest way to [install](https://github.com/SimonG96/LightweightIocContainer/wiki/Install-Lightweight-IOC-Container) the Lightweight IOC Container is by using [NuGet](https://www.nuget.org/packages/LightweightIocContainer/) through the [`.NET CLI`](https://github.com/SimonG96/LightweightIocContainer/wiki/Install-Lightweight-IOC-Container#net-cli): The easiest way to [install](https://github.com/SimonG96/LightweightIocContainer/wiki/Install-Lightweight-IOC-Container) the Lightweight IOC Container is by using [NuGet](https://www.nuget.org/packages/LightweightIocContainer/) through the [`.NET CLI`](https://github.com/SimonG96/LightweightIocContainer/wiki/Install-Lightweight-IOC-Container#net-cli):
```.net ```.net
> dotnet add package LightweightIocContainer --version 4.4.0-beta2 > dotnet add package LightweightIocContainer --version 4.4.0
``` ```
### Example usage ### Example usage
@ -59,7 +59,7 @@ The easiest way to [install](https://github.com/SimonG96/LightweightIocContainer
There is the option to install the [LightweightIocContainer.Validation](https://www.nuget.org/packages/LightweightIocContainer.Validation/) package: There is the option to install the [LightweightIocContainer.Validation](https://www.nuget.org/packages/LightweightIocContainer.Validation/) package:
```.net ```.net
> dotnet add package LightweightIocContainer.Validaton --version 4.4.0-beta2 > dotnet add package LightweightIocContainer.Validaton --version 4.4.0
``` ```
With this you can validate your `IocContainer` setup by using the `IocValidator` in a unit test: With this you can validate your `IocContainer` setup by using the `IocValidator` in a unit test:

@ -31,9 +31,13 @@ public class DisposeStrategyTest
} }
} }
private class TestNotDisposable private class TestNotDisposable;
[UsedImplicitly]
public interface IInterfaceSegregation : ITest;
private class TestInterfaceSegregation : IInterfaceSegregation
{ {
public void Dispose() => throw new Exception();
} }
@ -119,4 +123,15 @@ public class DisposeStrategyTest
IocContainer iocContainer = new(); IocContainer iocContainer = new();
Assert.Throws<InvalidDisposeStrategyException>(() => iocContainer.Register(r => r.Add<TestNotDisposable>(Lifestyle.Singleton).WithDisposeStrategy(DisposeStrategy.Container))); Assert.Throws<InvalidDisposeStrategyException>(() => iocContainer.Register(r => r.Add<TestNotDisposable>(Lifestyle.Singleton).WithDisposeStrategy(DisposeStrategy.Container)));
} }
[Test]
public void TestValidDisposeStrategyForSingletonInterfaceSegregation()
{
IocContainer iocContainer = new();
iocContainer.Register(r => r.Add<ITest, IInterfaceSegregation, TestInterfaceSegregation>(Lifestyle.Singleton).WithDisposeStrategy(DisposeStrategy.Application));
iocContainer.Resolve<ITest>();
Assert.DoesNotThrow(() => iocContainer.Dispose());
}
} }
Loading…
Cancel
Save