Skip to content

Commit

Permalink
Update to 1.2.0:
Browse files Browse the repository at this point in the history
 - Added: Non-generic service registration overloads.
 - Updated: Nuget Metadata.
 - Updated: README.md.
  • Loading branch information
ApacheTech committed Jan 25, 2022
1 parent 8547005 commit 1ec0ec0
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,23 @@ public interface IServiceCollection
/// </summary>
/// <param name="descriptor">The pre-populated descriptor for the service to register.</param>
/// <seealso cref="ServiceDescriptor"/>
///
void Register(ServiceDescriptor descriptor);

/// <summary>
/// Registers a service as a singleton. Only one instance of the service will be created within the container.
/// </summary>
/// <param name="implementationType">The type of implementation to use.</param>
/// <seealso cref="ServiceLifetime.Singleton"/>
void RegisterSingleton(Type implementationType);

/// <summary>
/// Registers a service as a singleton. Only one instance of the service will be created within the container.
/// </summary>
/// <param name="serviceType">The type of service to register.</param>
/// <param name="implementationType">The type of implementation to use.</param>
/// <seealso cref="ServiceLifetime.Singleton"/>
void RegisterSingleton(Type serviceType, Type implementationType);

/// <summary>
/// Registers a service as a singleton. Only one instance of the service will be created within the container.
/// </summary>
Expand Down Expand Up @@ -49,6 +63,21 @@ public interface IServiceCollection
/// <seealso cref="ServiceLifetime.Singleton"/>
void RegisterSingleton<TService>(TService implementation);

/// <summary>
/// Registers a service as a singleton. A new instance of the service will be created each time it is resolved.
/// </summary>
/// <param name="implementationType">The type of implementation to use.</param>
/// <seealso cref="ServiceLifetime.Transient"/>
void RegisterTransient(Type implementationType);

/// <summary>
/// Registers a service as a singleton. A new instance of the service will be created each time it is resolved.
/// </summary>
/// <param name="serviceType">The type of service to register.</param>
/// <param name="implementationType">The type of implementation to use.</param>
/// <seealso cref="ServiceLifetime.Transient"/>
void RegisterTransient(Type serviceType, Type implementationType);

/// <summary>
/// Registers a service as a singleton. A new instance of the service will be created each time it is resolved.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<Title>Minimal Dependency Injection Engine</Title>

<Version>1.1.0.0</Version>
<Version>1.2.0.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion ApacheTech.Common.DependencyInjection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ The original purpose of this package was to act as an IOC container for game mod

## Acknowledgement:

Inspired by Nick Chapsas' video tutorial on bespoke dependency injection solutions.
Inspired by Nick Chapsas' video tutorial on bespoke dependency injection solutions.

https://www.youtube.com/watch?v=NSVZa4JuTl8
42 changes: 42 additions & 0 deletions ApacheTech.Common.DependencyInjection/ServiceCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@ public void Register(ServiceDescriptor descriptor)
_serviceDescriptors.AddIfNotPresent(descriptor);
}

/// <summary>
/// Registers a service as a singleton. Only one instance of the service will be created within the container.
/// </summary>
/// <param name="implementationType">The type of implementation to use.</param>
/// <seealso cref="ServiceLifetime.Singleton" />
public void RegisterSingleton(Type implementationType)
{
_serviceDescriptors.AddIfNotPresent(new ServiceDescriptor(implementationType, ServiceLifetime.Singleton));
}

/// <summary>
/// Registers a service as a singleton. Only one instance of the service will be created within the container.
/// </summary>
/// <param name="serviceType">The type of service to register.</param>
/// <param name="implementationType">The type of implementation to use.</param>
/// <seealso cref="ServiceLifetime.Singleton" />
public void RegisterSingleton(Type serviceType, Type implementationType)
{
_serviceDescriptors.AddIfNotPresent(new ServiceDescriptor(serviceType, implementationType, ServiceLifetime.Singleton));
}

/// <summary>
/// Registers a service as a singleton. Only one instance of the service will be created within the container.
/// </summary>
Expand Down Expand Up @@ -79,6 +100,27 @@ public void RegisterSingleton<TService>(TService instance)
_serviceDescriptors.AddIfNotPresent(new ServiceDescriptor(typeof(TService), instance, ServiceLifetime.Singleton));
}

/// <summary>
/// Registers a service as a singleton. A new instance of the service will be created each time it is resolved.
/// </summary>
/// <param name="implementationType">The type of implementation to use.</param>
/// <seealso cref="ServiceLifetime.Transient" />
public void RegisterTransient(Type implementationType)
{
_serviceDescriptors.AddIfNotPresent(new ServiceDescriptor(implementationType, ServiceLifetime.Transient));
}

/// <summary>
/// Registers a service as a singleton. A new instance of the service will be created each time it is resolved.
/// </summary>
/// <param name="serviceType">The type of service to register.</param>
/// <param name="implementationType">The type of implementation to use.</param>
/// <seealso cref="ServiceLifetime.Transient" />
public void RegisterTransient(Type serviceType, Type implementationType)
{
_serviceDescriptors.AddIfNotPresent(new ServiceDescriptor(serviceType, implementationType, ServiceLifetime.Transient));
}

/// <summary>
/// Registers a service as a singleton. A new instance of the service will be created each time it is resolved.
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ The original purpose of this package was to act as an IOC container for game mod

## Acknowledgement:

Inspired by Nick Chapsas' video tutorial on bespoke dependency injection solutions.
Inspired by Nick Chapsas' video tutorial on bespoke dependency injection solutions.

https://www.youtube.com/watch?v=NSVZa4JuTl8

0 comments on commit 1ec0ec0

Please sign in to comment.