Skip to content

Add-on functionality to .Net Platform Extensions (Microsoft.Extensions.*)

License

Notifications You must be signed in to change notification settings

xpike/microsoft-extensions

Repository files navigation

XPike.Extensions.DependencyInjection

Build Status Nuget

Introduction

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.

Usage

Verifying the Container

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();
}

Using Microsoft.Extensions.DependencyInjection in Legacy WebAPI

Building and Testing

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

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:

  1. A detailed description of the problem
  2. Steps to reproduce
  3. Expected results
  4. Actual results
  5. Version of the package xPike
  6. Version of the .Net runtime

Contributing

See our contributing guidelines in our documentation for information on how to contribute to xPike.

License

xPike is licensed under the MIT License.

About

Add-on functionality to .Net Platform Extensions (Microsoft.Extensions.*)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages