250
CHAPTER 6 | Tackle Business Complexity in a Microservice with DDD and CQRS Patterns
// Add framework services.
builder.
Services
.
AddMvc
(options =>
{
options.
Filters
.
Add
(
typeof
(HttpGlobalExceptionFilter));
}).
AddControllersAsServices
();
builder.
Services
.
AddEntityFrameworkSqlServer
()
.
AddDbContext
(options =>
{
options.
UseSqlServer
(Configuration[
"ConnectionString"
],
sqlOptions =>
sqlOptions.
MigrationsAssembly
(
typeof
(Startup).
GetTypeInfo
().
Assembly.
GetName
().
Name
));
},
ServiceLifetime.
Scoped
// Note that Scoped is the default choice
// in AddDbContext. It is shown here only for
// pedagogic purposes.
);
The DbContext instantiation mode should not be configured as ServiceLifetime.Transient or
ServiceLifetime.Singleton.
Dostları ilə paylaş: