ForEvolve.DependencyInjection.ContextualBindings 0.0.0-github.3

This is a prerelease version of ForEvolve.DependencyInjection.ContextualBindings.
There is a newer version of this package available.
See the version list below for details.
dotnet add package ForEvolve.DependencyInjection.ContextualBindings --version 0.0.0-github.3
NuGet\Install-Package ForEvolve.DependencyInjection.ContextualBindings -Version 0.0.0-github.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ForEvolve.DependencyInjection.ContextualBindings" Version="0.0.0-github.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ForEvolve.DependencyInjection.ContextualBindings --version 0.0.0-github.3
#r "nuget: ForEvolve.DependencyInjection.ContextualBindings, 0.0.0-github.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ForEvolve.DependencyInjection.ContextualBindings as a Cake Addin
#addin nuget:?package=ForEvolve.DependencyInjection.ContextualBindings&version=0.0.0-github.3&prerelease

// Install ForEvolve.DependencyInjection.ContextualBindings as a Cake Tool
#tool nuget:?package=ForEvolve.DependencyInjection.ContextualBindings&version=0.0.0-github.3&prerelease

ForEvolve.DependencyInjection

Build, Test, and Deploy master to feedz.io feedz.io

Asp.Net Core dependency injection utilities. This project aims at adding a few missing pieces to the Asp.Net Core container, without the need to replace it by a third-party.

The current plan is:

  • Contextual dependency injection
  • Automatic factory creation, based on interfaces

Contextual Bindings

This is an early work in progress, and the API will likely change over time.

The goal of this library is to add support for contextual dependency injection. The extended goal would be to allow building complex object trees, conditionally, allowing for more flexibility than a single binding per service.

What is currently working:

  • Transient contextual injection
  • Scoped contextual injection
  • Singleton contextual injection

What is not working yet:

  • Contextual injection in MVC controllers
  • Contextual object trees building (using a service providers tree to manage the complexity)

A few other mixed use-cases could also work, but use at your own risks!

AutoFactory

The work on this project is not yet started

The goal of this library is to generate factories automatically, based on an interface. For example, the idea would be to implement the following interface automatically.

public interface IFactory
{
    IService CreateService();
}

The initial implementation would be a simple service locator, that gets IService from the container. The design may change along the way to support more complex scenarios.

How to use

Feel free to look at the tests and the sample projects to get an idea of the possibilities.

Install

At some point there will be some packages; until then, here is the name they will have:

dotnet add package ForEvolve.DependencyInjection.AutoFactory
dotnet add package ForEvolve.DependencyInjection.ContextualBindings

Simple Contextual Bindings

You can inject contextual implementation into different classes, like:

// Inject a LastNameGenerator instance into the INameGenerator parameter of FirstNameService
services
    .AddContextualBinding<IFirstNameService, FirstNameService>()
    .WithConstructorArgument<INameGenerator, FirstNameGenerator>()
;
// Inject a LastNameGenerator instance into the INameGenerator parameter of LastNameService
services
    .AddContextualBinding<ILastNameService, LastNameService>()
    .WithConstructorArgument<INameGenerator, LastNameGenerator>()
;
// Inject a FirstNameGenerator in the first INameGenerator parameter and
// inject a LastNameGenerator in the second INameGenerator parameter of FullNameGenerator.
services
    .AddContextualBinding<INameGenerator, FullNameGenerator>()
    .WithConstructorArgument<INameGenerator, FirstNameGenerator>()
    .WithConstructorArgument<INameGenerator, LastNameGenerator>()
;

How to contribute?

If you would like to contribute to the project, first, thank you for your interest, and please read Contributing to ForEvolve open source projects for more information.

Contributor Covenant Code of Conduct

Also, please read the Contributor Covenant Code of Conduct that applies to all ForEvolve repositories.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on ForEvolve.DependencyInjection.ContextualBindings:

Package Downloads
ForEvolve.DependencyInjection

Package Description

ForEvolve.DependencyInjection.ContextualBindings.AspNetCore

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.5 986 11/10/2020
1.0.12 961 6/2/2020
1.0.10 999 6/2/2020
1.0.8 1,260 2/19/2020
0.0.0-github.3 286 1/27/2020