Last active
December 16, 2019 09:38
-
-
Save takahirohonda/eb72d4a325b310b986e24b1723c23a3f to your computer and use it in GitHub Desktop.
Using Attribute - ASP.NET Core DI
This file contains hidden or 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
// Add attribute | |
// Interface for the class & Lifetime | |
// (1) Scoped | |
[Service(typeof(IAppsRepository), Lifetime.Scoped)] | |
public class AppsRepository : IAppsRepository | |
{ | |
... | |
} | |
// (2) Transient | |
[Service(typeof(IAppsRepository), Lifetime.Transient)] | |
public class AppsRepository : IAppsRepository | |
{ | |
... | |
} | |
// (3) Singleton | |
[Service(typeof(IAppsRepository), Lifetime.Singleton)] | |
public class AppsRepository : IAppsRepository | |
{ | |
... | |
} | |
// (4) Generics | |
[Service(typeof(IAppLogger<>), Lifetime.Scoped)] | |
public class LoggerAdapter<T> : IAppLogger<T> | |
{ | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment