Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include BoDi to Reqnroll package (#91) #95

Merged
merged 4 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
920 changes: 0 additions & 920 deletions Reqnroll.BoDi/BoDi.cs

This file was deleted.

22 changes: 0 additions & 22 deletions Reqnroll.BoDi/Reqnroll.BoDi.csproj

This file was deleted.

16 changes: 1 addition & 15 deletions Reqnroll.sln
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GitHubWorkflows", "GitHubWo
.github\workflows\lock.yml = .github\workflows\lock.yml
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Reqnroll.BoDi", "Reqnroll.BoDi\Reqnroll.BoDi.csproj", "{8E1AB4D0-98E8-46C5-97EC-7EF47B5DFD27}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Reqnroll.SystemTests", "Tests\Reqnroll.SystemTests\Reqnroll.SystemTests.csproj", "{C658B37D-FD36-4868-9070-4EB452FAE526}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Reqnroll.SystemTests", "Tests\Reqnroll.SystemTests\Reqnroll.SystemTests.csproj", "{C658B37D-FD36-4868-9070-4EB452FAE526}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -515,18 +513,6 @@ Global
{C073A609-8A6A-4707-86B0-7BB32EF8ACEE}.Release|Any CPU.Build.0 = Release|Any CPU
{C073A609-8A6A-4707-86B0-7BB32EF8ACEE}.VS2010IntegrationTest|Any CPU.ActiveCfg = Debug|Any CPU
{C073A609-8A6A-4707-86B0-7BB32EF8ACEE}.VS2010IntegrationTest|Any CPU.Build.0 = Debug|Any CPU
{8E1AB4D0-98E8-46C5-97EC-7EF47B5DFD27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E1AB4D0-98E8-46C5-97EC-7EF47B5DFD27}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E1AB4D0-98E8-46C5-97EC-7EF47B5DFD27}.Debug-MSTest|Any CPU.ActiveCfg = Debug|Any CPU
{8E1AB4D0-98E8-46C5-97EC-7EF47B5DFD27}.Debug-MSTest|Any CPU.Build.0 = Debug|Any CPU
{8E1AB4D0-98E8-46C5-97EC-7EF47B5DFD27}.Debug-NUnit|Any CPU.ActiveCfg = Debug|Any CPU
{8E1AB4D0-98E8-46C5-97EC-7EF47B5DFD27}.Debug-NUnit|Any CPU.Build.0 = Debug|Any CPU
{8E1AB4D0-98E8-46C5-97EC-7EF47B5DFD27}.Debug-XUnit|Any CPU.ActiveCfg = Debug|Any CPU
{8E1AB4D0-98E8-46C5-97EC-7EF47B5DFD27}.Debug-XUnit|Any CPU.Build.0 = Debug|Any CPU
{8E1AB4D0-98E8-46C5-97EC-7EF47B5DFD27}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E1AB4D0-98E8-46C5-97EC-7EF47B5DFD27}.Release|Any CPU.Build.0 = Release|Any CPU
{8E1AB4D0-98E8-46C5-97EC-7EF47B5DFD27}.VS2010IntegrationTest|Any CPU.ActiveCfg = Debug|Any CPU
{8E1AB4D0-98E8-46C5-97EC-7EF47B5DFD27}.VS2010IntegrationTest|Any CPU.Build.0 = Debug|Any CPU
{C658B37D-FD36-4868-9070-4EB452FAE526}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C658B37D-FD36-4868-9070-4EB452FAE526}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C658B37D-FD36-4868-9070-4EB452FAE526}.Debug-MSTest|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down
6 changes: 6 additions & 0 deletions Reqnroll/BoDi/IContainedInstance.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Reqnroll.BoDi;

public interface IContainedInstance
{
IObjectContainer Container { get; }
}
117 changes: 117 additions & 0 deletions Reqnroll/BoDi/IObjectContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using System;
using System.Collections.Generic;

namespace Reqnroll.BoDi;

public interface IObjectContainer : IDisposable
{
/// <summary>
/// Fired when a new object is created directly by the container. It is not invoked for resolving instance and factory registrations.
/// </summary>
event Action<object> ObjectCreated;

/// <summary>
/// Registers a type as the desired implementation type of an interface.
/// </summary>
/// <typeparam name="TType">Implementation type</typeparam>
/// <typeparam name="TInterface">Interface will be resolved</typeparam>
/// <returns>An object which allows to change resolving strategy.</returns>
/// <param name="name">A name to register named instance, otherwise null.</param>
/// <exception cref="ObjectContainerException">If there was already a resolve for the <typeparamref name="TInterface"/>.</exception>
/// <remarks>
/// <para>Previous registrations can be overridden before the first resolution for the <typeparamref name="TInterface"/>.</para>
/// </remarks>
IStrategyRegistration RegisterTypeAs<TType, TInterface>(string name = null) where TType : class, TInterface;

/// <summary>
/// Registers an instance
/// </summary>
/// <typeparam name="TInterface">Interface will be resolved</typeparam>
/// <param name="instance">The instance implements the interface.</param>
/// <param name="name">A name to register named instance, otherwise null.</param>
/// <param name="dispose">Whether the instance should be disposed on container dispose, otherwise <c>false</c>.</param>
/// <exception cref="ArgumentNullException">If <paramref name="instance"/> is null.</exception>
/// <exception cref="ObjectContainerException">If there was already a resolve for the <typeparamref name="TInterface"/>.</exception>
/// <remarks>
/// <para>Previous registrations can be overridden before the first resolution for the <typeparamref name="TInterface"/>.</para>
/// <para>The instance will be registered in the object pool, so if a <see cref="Resolve{T}()"/> (for another interface) would require an instance of the dynamic type of the <paramref name="instance"/>, the <paramref name="instance"/> will be returned.</para>
/// </remarks>
void RegisterInstanceAs<TInterface>(TInterface instance, string name = null, bool dispose = false) where TInterface : class;

/// <summary>
/// Registers an instance
/// </summary>
/// <param name="instance">The instance implements the interface.</param>
/// <param name="interfaceType">Interface will be resolved</param>
/// <param name="name">A name to register named instance, otherwise null.</param>
/// <param name="dispose">Whether the instance should be disposed on container dispose, otherwise <c>false</c>.</param>
/// <exception cref="ArgumentNullException">If <paramref name="instance"/> is null.</exception>
/// <exception cref="ObjectContainerException">If there was already a resolve for the <paramref name="interfaceType"/>.</exception>
/// <remarks>
/// <para>Previous registrations can be overridden before the first resolution for the <paramref name="interfaceType"/>.</para>
/// <para>The instance will be registered in the object pool, so if a <see cref="Resolve{T}()"/> (for another interface) would require an instance of the dynamic type of the <paramref name="instance"/>, the <paramref name="instance"/> will be returned.</para>
/// </remarks>
void RegisterInstanceAs(object instance, Type interfaceType, string name = null, bool dispose = false);

/// <summary>
/// Registers an instance produced by <paramref name="factoryDelegate"/>. The delegate will be called only once and the instance it returned will be returned in each resolution.
/// </summary>
/// <typeparam name="TInterface">Interface to register as.</typeparam>
/// <param name="factoryDelegate">The function to run to obtain the instance.</param>
/// <param name="name">A name to resolve named instance, otherwise null.</param>
IStrategyRegistration RegisterFactoryAs<TInterface>(Func<IObjectContainer, TInterface> factoryDelegate, string name = null);

/// <summary>
/// Resolves an implementation object for an interface or type.
/// </summary>
/// <typeparam name="T">The interface or type.</typeparam>
/// <returns>An object implementing <typeparamref name="T"/>.</returns>
/// <remarks>
/// <para>The container pools the objects, so if the interface is resolved twice or the same type is registered for multiple interfaces, a single instance is created and returned.</para>
/// </remarks>
T Resolve<T>();

/// <summary>
/// Resolves an implementation object for an interface or type.
/// </summary>
/// <param name="name">A name to resolve named instance, otherwise null.</param>
/// <typeparam name="T">The interface or type.</typeparam>
/// <returns>An object implementing <typeparamref name="T"/>.</returns>
/// <remarks>
/// <para>The container pools the objects, so if the interface is resolved twice or the same type is registered for multiple interfaces, a single instance is created and returned.</para>
/// </remarks>
T Resolve<T>(string name);

/// <summary>
/// Resolves an implementation object for an interface or type.
/// </summary>
/// <param name="typeToResolve">The interface or type.</param>
/// <param name="name">A name to resolve named instance, otherwise null.</param>
/// <returns>An object implementing <paramref name="typeToResolve"/>.</returns>
/// <remarks>
/// <para>The container pools the objects, so if the interface is resolved twice or the same type is registered for multiple interfaces, a single instance is created and returned.</para>
/// </remarks>
object Resolve(Type typeToResolve, string name = null);

/// <summary>
/// Resolves all implementations of an interface or type.
/// </summary>
/// <typeparam name="T">The interface or type.</typeparam>
/// <returns>An object implementing <typeparamref name="T"/>.</returns>
IEnumerable<T> ResolveAll<T>() where T : class;

/// <summary>
/// Determines whether the interface or type is registered.
/// </summary>
/// <typeparam name="T">The interface or type.</typeparam>
/// <returns><c>true</c> if the interface or type is registered; otherwise <c>false</c>.</returns>
bool IsRegistered<T>();

/// <summary>
/// Determines whether the interface or type is registered with the specified name.
/// </summary>
/// <typeparam name="T">The interface or type.</typeparam>
/// <param name="name">The name.</param>
/// <returns><c>true</c> if the interface or type is registered; otherwise <c>false</c>.</returns>
bool IsRegistered<T>(string name);
}
15 changes: 15 additions & 0 deletions Reqnroll/BoDi/IStrategyRegistration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Reqnroll.BoDi;

public interface IStrategyRegistration
{
/// <summary>
/// Changes resolving strategy to a new instance per each dependency.
/// </summary>
/// <returns></returns>
IStrategyRegistration InstancePerDependency();
/// <summary>
/// Changes resolving strategy to a single instance per object container. This strategy is a default behaviour.
/// </summary>
/// <returns></returns>
IStrategyRegistration InstancePerContext();
}
Loading
Loading