KuraiAndras / Extenject.Microsoft

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extenject.Microsoft openupm

Use Microsoft.Extensions.DependencyInjection.Abstractions interfaces with Extenject/Zenject.

Implemented types

  • IServiceCollection
  • IServiceProvider
  • IServiceScope
  • IServiceScopeFactory

Installation

Install it via OpenUPM

openupm add com.extenject.microsoft

You will also need to provide the Microsoft.Extensions.DependencyInjection.Abstractions DLL for your unity project. This package was tested with the 5.0.0 version, but other versions should also work.

Usage

Use the DiTranslator, with the Translate extension method on IServiceCollection to translate Microsoft bindings to Extenject/Zenject

public sealed class SampleInstaller : MonoInstaller
{
    private readonly IServiceCollection _serviceCollection = new ExtenjectServiceCollection();

    public override void InstallBindings()
    {
        _serviceCollection.AddTransient<IMyService, MyService>();
        _serviceCollection.AddScoped<IService, Service>();
        _serviceCollection.AddSingleton<ISingleton, Singleton>();

        _serviceCollection.Translate(Container); // This will translate the bindings into the provided DiContainer
    }
}

About

License:MIT License


Languages

Language:C# 100.0%