Make using scoped services in notification handlers less painful. (#11733)

* Add failing test to demo issue with handlers + scoped dependencies.

* Make using scoped services in notification handlers less painful.

* Update comments for accuracy.
This commit is contained in:
Paul Johnson
2022-01-10 15:31:46 +00:00
committed by GitHub
parent 187cac469e
commit a952d17e74
4 changed files with 143 additions and 6 deletions

View File

@@ -87,7 +87,16 @@ namespace Umbraco.Cms.Tests.Integration.TestServerTest
// call startup
builder.Configure(app => Configure(app));
}).UseEnvironment(Environments.Development);
})
.UseDefaultServiceProvider(cfg =>
{
// These default to true *if* WebHostEnvironment.EnvironmentName == Development
// When running tests, EnvironmentName used to be null on the mock that we register into services.
// Enable opt in for tests so that validation occurs regardless of environment name.
// Would be nice to have this on for UmbracoIntegrationTest also but requires a lot more effort to resolve issues.
cfg.ValidateOnBuild = true;
cfg.ValidateScopes = true;
});
return builder;
}