Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/vb2ae/vb2ae.servicelocator.msdependencyinjection

A class to allow you to register the Microsoft.Extensions.DependencyInjection with the CommonServiceLocator
https://github.com/vb2ae/vb2ae.servicelocator.msdependencyinjection

common-service-locator dependency-injection service-locator service-locator-pattern

Last synced: about 1 month ago
JSON representation

A class to allow you to register the Microsoft.Extensions.DependencyInjection with the CommonServiceLocator

Awesome Lists containing this project

README

        

# vb2ae.ServiceLocator.MSDependencyInjection
[![.NET](https://github.com/vb2ae/vb2ae.ServiceLocator.MSDependencyInjection/actions/workflows/dotnet.yml/badge.svg)](https://github.com/vb2ae/vb2ae.ServiceLocator.MSDependencyInjection/actions/workflows/dotnet.yml)

[![CodeQL](https://github.com/vb2ae/vb2ae.ServiceLocator.MSDependencyInjection/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/vb2ae/vb2ae.ServiceLocator.MSDependencyInjection/actions/workflows/github-code-scanning/codeql)

[![Dependabot Updates](https://github.com/vb2ae/vb2ae.ServiceLocator.MSDependencyInjection/actions/workflows/dependabot/dependabot-updates/badge.svg)](https://github.com/vb2ae/vb2ae.ServiceLocator.MSDependencyInjection/actions/workflows/dependabot/dependabot-updates)

![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/vb2ae/066c4effbbf4ea1ea1e62f172bde53fa/raw/service-locator-code-coverage.json)

The purpose of this class library is to be able to use Microsoft.Extensions.DependencyInjection with the common service locator.

## example
private IServiceProvider Build()
{
if (_built)
throw new InvalidOperationException("Build can only be called once.");
_built = true;

_defaultBuilder.ConfigureServices((context, services) =>
{
services.AddSingleton();
// where ServiceImpl implements IService
// ... add other services when needed
});

_services = _defaultBuilder.Build().Services;
CommonServiceLocator.ServiceLocator.SetLocatorProvider(() => new vb2ae.ServiceLocator.MSDependencyInjection.MSDependencyInjectionServiceLocator(_services));
return _services;
}