Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/vb2ae/vb2ae.servicelocator.msdependencyinjection
- Owner: vb2ae
- Created: 2024-09-30T10:57:56.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2024-11-19T00:53:00.000Z (about 2 months ago)
- Last Synced: 2024-11-19T01:47:26.093Z (about 2 months ago)
- Topics: common-service-locator, dependency-injection, service-locator, service-locator-pattern
- Language: C#
- Homepage:
- Size: 33.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
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;
}