This library provides extensions/enhancements to Microsoft.Extensions.DependencyInjection. It is independent of the xPike paved-road SDKs and takes no dependencies on the rest of xPike.
A common mistake we make is forgetting to register a type with the container. Another is having a singleton depend on a
transient (or other lesser scoped) registration. xPike Extensions solves this by providing the cabability to verify
your IServiceProvider
instance at startup.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
...
services.AddServiceProviderVerification();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.ApplicationServices.Verify();
...
app.UseMvc();
}
This ensures that:
- All root objects and their dependencies can be resolved.
- Singletons only depend on other singletons.
- Scoped registrations only depend on singletons and other scoped registrations.
This can signifcantly reduce production issues caused by missing or improper registrations not identified during testing.
There is a performance hit at startup. The impact depends on the number of registrations.
You may want to only verify the container in non-production environments. Assuming you have your
ASPNETCORE_ENVIRONMENT
set properly for each environment, you can simply...
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (!env.IsProduction())
app.ApplicationServices.Verify();
...
app.UseMvc();
}
Building from source and running unit tests requires a Windows machine with:
- .Net Core 3.0 SDK
- .Net Framework 4.6.1 Developer Pack
Issues are tracked on GitHub. Anyone is welcome to file a bug, an enhancement request, or ask a general question. We ask that bug reports include:
- A detailed description of the problem
- Steps to reproduce
- Expected results
- Actual results
- Version of the package xPike
- Version of the .Net runtime
See our contributing guidelines in our documentation for information on how to contribute to xPike.
xPike is licensed under the MIT License.