Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Created April 24, 2021 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj-choudhari-git/55a9496fd05b76eecbd9cc15ee152b09 to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/55a9496fd05b76eecbd9cc15ee152b09 to your computer and use it in GitHub Desktop.
Invoker which expects objects having different service lifetimes
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