-
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 #18 from rena0157/adding-lifetime-options
Adding lifetime options
- Loading branch information
Showing
5 changed files
with
157 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
|
||
namespace Mapr; | ||
|
||
/// <summary> | ||
/// Represents an attribute that can be placed on map classes to control their behavior | ||
/// and registration. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class)] | ||
public class MapAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// Gets or sets the lifetime for the map. Determining how it will be registered in the | ||
/// DI container. The default is <see cref="MapLifetime.Transient"/>. | ||
/// </summary> | ||
public MapLifetime Lifetime { get; set; } = MapLifetime.Transient; | ||
} | ||
|
||
/// <summary> | ||
/// Represents the different lifetimes that can be used to register a map. | ||
/// </summary> | ||
public enum MapLifetime | ||
{ | ||
/// <summary> | ||
/// Registers the map as a singleton. | ||
/// </summary> | ||
Singleton, | ||
|
||
/// <summary> | ||
/// Registers the map as a transient. | ||
/// </summary> | ||
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
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,11 @@ | ||
namespace Mapr.DependencyInjection.Tests; | ||
|
||
[Map(Lifetime = MapLifetime.Singleton)] | ||
public class TestSingletonMap: IMap<string, string> | ||
{ | ||
/// <inheritdoc /> | ||
public string Map(string source) | ||
{ | ||
return source; | ||
} | ||
} |