-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adding the ability to register types via attribute
* The most significant changes involve the addition of a new attribute-based registration feature. This feature allows classes and interfaces to be registered with Canister using the `RegisterAttribute` and `RegisterAllAttribute` attributes. * The `dotnet-publish.yml` file was also updated to publish coverage reports to coveralls.io.
- Loading branch information
Showing
8 changed files
with
318 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System; | ||
|
||
namespace Canister.IoC.Attributes | ||
{ | ||
/// <summary> | ||
/// This attribute is used to register all items of a specific type with Canister and is used to | ||
/// mark a type for registration. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Interface, AllowMultiple = false)] | ||
public class RegisterAllAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
public RegisterAllAttribute() | ||
{ | ||
Lifetime = ServiceLifetime.Transient; | ||
} | ||
|
||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="lifetime">Lifetime of the service</param> | ||
public RegisterAllAttribute(ServiceLifetime lifetime) | ||
{ | ||
Lifetime = lifetime; | ||
} | ||
|
||
/// <summary> | ||
/// The lifetime of the service. | ||
/// </summary> | ||
public ServiceLifetime Lifetime { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System; | ||
|
||
namespace Canister.IoC.Attributes | ||
{ | ||
/// <summary> | ||
/// This attribute is used to register a type with Canister and is used to mark a type for registration. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false)] | ||
public class RegisterAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
public RegisterAttribute() | ||
{ | ||
Lifetime = ServiceLifetime.Transient; | ||
} | ||
|
||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="lifetime">Lifetime of the service</param> | ||
/// <param name="serviceKey">The service key to register as (if any)</param> | ||
public RegisterAttribute(ServiceLifetime lifetime, object? serviceKey = null) | ||
{ | ||
Lifetime = lifetime; | ||
ServiceKey = serviceKey; | ||
} | ||
|
||
/// <summary> | ||
/// The lifetime of the service. | ||
/// </summary> | ||
public ServiceLifetime Lifetime { get; set; } | ||
|
||
/// <summary> | ||
/// The service key to register as (if any). | ||
/// </summary> | ||
public object? ServiceKey { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.