In this recipe, we will see an example with all the life cycles available and look at what it involves.
- First, let's create an interface named
IOperation
with a getter on aGuid
type, and four interfaces that represent a task for each life cycle available:
- We will now implement these interfaces in an
Operation
class:
- In the
ConfigurationServices
method of theStartup.cs
class, we manage the lifetime for each interface:
- Now, let's create an
OperationService
class that we will use in an MVC controller and execute in several HTTP requests:
- Now, we create the MVC controller and add an
Index
action to show the value ofGuid
for each implementation:
- Finally, we create the view that shows the result: