-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from Tim-Maes/feature/keyed-services
Support for Keyed Services
- Loading branch information
Showing
11 changed files
with
214 additions
and
30 deletions.
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
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,23 @@ | ||
namespace Bindicate.Attributes; | ||
|
||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] | ||
public abstract class BaseKeyedServiceAttribute : Attribute | ||
{ | ||
public Type ServiceType { get; protected set; } | ||
public object Key { get; protected set; } // Added key property | ||
|
||
public abstract Lifetime.Lifetime Lifetime { get; } | ||
|
||
// Constructor for class-only registration without a key | ||
protected BaseKeyedServiceAttribute() | ||
Check warning on line 12 in src/Bindicate/Attributes/BaseKeyedServiceAttribute.cs GitHub Actions / run_test
Check warning on line 12 in src/Bindicate/Attributes/BaseKeyedServiceAttribute.cs GitHub Actions / run_test
Check warning on line 12 in src/Bindicate/Attributes/BaseKeyedServiceAttribute.cs GitHub Actions / create_nuget
|
||
{ | ||
ServiceType = null; | ||
Check warning on line 14 in src/Bindicate/Attributes/BaseKeyedServiceAttribute.cs GitHub Actions / run_test
|
||
} | ||
|
||
// Constructor for explicit interface registration with a key | ||
protected BaseKeyedServiceAttribute(object key, Type serviceType = null) | ||
Check warning on line 18 in src/Bindicate/Attributes/BaseKeyedServiceAttribute.cs GitHub Actions / run_test
|
||
{ | ||
Key = key; | ||
ServiceType = serviceType; | ||
} | ||
} |
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,15 @@ | ||
namespace Bindicate.Attributes.Scoped; | ||
|
||
/// <summary> | ||
/// Specifies that a service should be registered with the dependency injection container with a specified key. | ||
/// </summary> | ||
public class AddKeyedScopedAttribute : BaseKeyedServiceAttribute | ||
{ | ||
public AddKeyedScopedAttribute(object key, Type serviceType) | ||
: base(key, serviceType) | ||
{ | ||
} | ||
|
||
public override Lifetime.Lifetime Lifetime => Bindicate.Lifetime.Lifetime.Scoped; | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/Bindicate/Attributes/Singleton/AddKeyedSingletonAttribute.cs
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,14 @@ | ||
namespace Bindicate.Attributes.Singleton; | ||
|
||
/// <summary> | ||
/// Specifies that a service should be registered with the dependency injection container with a specified key. | ||
/// </summary> | ||
public class AddKeyedSingletonAttribute : BaseKeyedServiceAttribute | ||
{ | ||
public AddKeyedSingletonAttribute(object key, Type serviceType) | ||
: base(key, serviceType) | ||
{ | ||
} | ||
|
||
public override Lifetime.Lifetime Lifetime => Bindicate.Lifetime.Lifetime.Singleton; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Bindicate/Attributes/Transient/AddKeyedTransientAttribute.cs
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,14 @@ | ||
namespace Bindicate.Attributes.Transient; | ||
|
||
/// <summary> | ||
/// Specifies that a service should be registered with the dependency injection container with a specified key. | ||
/// </summary> | ||
public class AddKeyedTransientAttribute : BaseKeyedServiceAttribute | ||
{ | ||
public AddKeyedTransientAttribute(object key, Type serviceType) | ||
: base(key, serviceType) | ||
{ | ||
} | ||
|
||
public override Lifetime.Lifetime Lifetime => Bindicate.Lifetime.Lifetime.Transient; | ||
} |
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.