Created
April 24, 2021 20:19
-
-
Save manoj-choudhari-git/55a9496fd05b76eecbd9cc15ee152b09 to your computer and use it in GitHub Desktop.
Invoker which expects objects having different service lifetimes
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
class GetCreatedTimeInvoker | |
{ | |
private readonly ISingletonGetCreatedTime singleton; | |
private readonly IScopedGetCreatedTime scoped; | |
private readonly ITransientGetCreatedTime transient; | |
public GetCreatedTimeInvoker(ISingletonGetCreatedTime singleton, | |
IScopedGetCreatedTime scoped, ITransientGetCreatedTime transient) | |
{ | |
this.singleton = singleton; | |
this.scoped = scoped; | |
this.transient = transient; | |
} | |
public void Invoke() | |
{ | |
Console.WriteLine($"Singleton Response: {singleton.GetCreatedTime():MM/dd/yyyy hh:mm:ss.fff tt}, Stays the same."); | |
Console.WriteLine($"Scoped Response: {scoped.GetCreatedTime():MM/dd/yyyy hh:mm:ss.fff tt}, Changes only if scope is changed"); | |
Console.WriteLine($"Transient Response: {transient.GetCreatedTime():MM/dd/yyyy hh:mm:ss.fff tt}, Changes everytime this method is invoked"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment