aspnetrun / run-aspnetcore-microservices

Microservices on .Net platforms which used ASP.NET Web API, Docker, RabbitMQ, MassTransit, Grpc, Yarp API Gateway, PostgreSQL, Redis, SQLite, SqlServer, Marten, Entity Framework Core, CQRS, MediatR, DDD, Vertical and Clean Architecture implementation with using latest features of .NET 8 and C# 12
https://www.udemy.com/course/microservices-architecture-and-implementation-on-dotnet/?couponCode=JUNE24
MIT License
2.53k stars 1.38k forks source link

Possible invalid lifetime for EmailService #26

Closed phorks closed 3 years ago

phorks commented 3 years ago

According to the course lectures, the reasoning behind registering the email service as transient is to prevent the service from being created for every request and to use a single instance throughout the application lifetime. This means that the service must be registered as singleton since transient means a new instance will be created EVERY TIME the service is requested from the dependency injection framework. Code

mehmetozkaya commented 3 years ago

so what is your recommendation ? should I use singleton on there ?

phorks commented 3 years ago

Yes. If you intend to have a single instance of EmailService for all requests, singleton is the appropriate lifetime.

mehmetozkaya commented 3 years ago

thanks for sharing this. I will consider and refactor this part. thanks.