Skip to content
Light weight library to enable directly injecting into requests in Asp.Net
C#
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
RequestInjector.NetCore
.gitignore
LICENSE
README.md
RequestInjector.NetCore.sln
icon.png

README.md

RequestInjector

Light weight library to enable directly injecting into requests in Asp.Net

Usage

For more info see my post on Request Injection. This uses the built in Microsoft Dependency Injection. Extensions for other IoC containers can be added if people want it. Add the package to your project and then register your depdendencies. Mark your requests with the IRequest interface. Example using Scrutor:

services.Scan(scan => scan
              .FromAssembliesOf(typeof(IRequest), typeof(GetTestRequest))
              .AddClasses()
              .AsSelf()
              .WithScopedLifetime());

After your dependencies are registered, add the following code to the StartUp:

var provider = services.BuildServiceProvider();

services.AddMvc(config =>
{
    config.ModelMetadataDetailsProviders.Add(new RequestInjectorMetadataProvider());
    config.ModelBinderProviders.Insert(0, new RequestInjectorModelBinderProvider());
})
.AddJsonOptions(options =>
{
    options.SerializerSettings.Converters.Add(new RequestInjectorHandler<IRequest>(provider));
});
You can’t perform that action at this time.