From 7f1e1d9c8cef420343e02c9af5b205533cc0a226 Mon Sep 17 00:00:00 2001 From: futurum-dev Date: Fri, 7 Apr 2023 11:24:04 +0100 Subject: [PATCH] Improve README.md. Nuget version bump for Futurum.Core to 1.0.15 Nuget version bump for Futurum.Test to 1.0.6 --- README.md | 72 ++++++++++++++++++- ...soft.Extensions.DependencyInjection.csproj | 4 +- ...xtensions.DependencyInjection.Tests.csproj | 4 +- 3 files changed, 73 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a935d9b..23261c8 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,76 @@ # Futurum.Microsoft.Extensions.DependencyInjection ![license](https://img.shields.io/github/license/futurum-dev/dotnet.futurum.microsoft.extensions.dependencyinjection?style=for-the-badge) -![CI](https://img.shields.io/github/workflow/status/futurum-dev/dotnet.futurum.microsoft.extensions.dependencyinjection/CI/main?style=for-the-badge) +![CI](https://img.shields.io/github/actions/workflow/status/futurum-dev/dotnet.futurum.microsoft.extensions.dependencyinjection/ci.yml?branch=main&style=for-the-badge) [![Coverage Status](https://img.shields.io/coveralls/github/futurum-dev/dotnet.futurum.microsoft.extensions.dependencyinjection?style=for-the-badge)](https://coveralls.io/github/futurum-dev/dotnet.futurum.microsoft.extensions.dependencyinjection?branch=main) [![NuGet version](https://img.shields.io/nuget/v/futurum.microsoft.extensions.dependencyinjection?style=for-the-badge)](https://www.nuget.org/packages/futurum.microsoft.extensions.dependencyinjection) -A dotnet library, that allows Microsoft.Extensions.DependencyInjection to work with Futurum.Core. +A dotnet library, that allows Microsoft.Extensions.DependencyInjection to work with Futurum.Core. It also adds support for modules and startables. -It also adds support for modules and startables. \ No newline at end of file +## TryGetService +Try to get the service object of the specified type. + +```csharp +var result = serviceProvider.TryGetService(); +``` + +## Modules +A module allows you to break up registration into logical units. + +### IModule interface +Implements this interface to create a module. + +```csharp +public class TestModule : IModule +{ + public void Load(IServiceCollection services) + { + services.AddSingleton(); + } +} +``` + +### RegisterModule extension method +Allows you to register a module. + +```csharp +services.RegisterModule(); +``` + +```csharp +services.RegisterModule(new TestModule()); +``` + +## Startables +A startable is resolved at the start of the application lifecycle and is a place to perform actions as soon as the DependencyInjection container is built. + +### IStartable interface +Implements this interface to create a startable. + +```csharp +public class TestStartable : IStartable +{ + public void Start() + { + // Do something + } +} +``` + +### AddStartable extension method +Allows you to register a startable. + +```csharp +services.AddStartable(); +``` + +```csharp +services.AddStartable(new TestStartable()); +``` + +### BuildServiceProviderWithStartables extension method +Creates a ServiceProvider containing services from the provided IServiceCollection and starts all *IStartable* instances. + +```csharp +var serviceProvider = services.BuildServiceProviderWithStartables(); +``` \ No newline at end of file diff --git a/src/Futurum.Microsoft.Extensions.DependencyInjection/Futurum.Microsoft.Extensions.DependencyInjection.csproj b/src/Futurum.Microsoft.Extensions.DependencyInjection/Futurum.Microsoft.Extensions.DependencyInjection.csproj index bc404d7..966e482 100644 --- a/src/Futurum.Microsoft.Extensions.DependencyInjection/Futurum.Microsoft.Extensions.DependencyInjection.csproj +++ b/src/Futurum.Microsoft.Extensions.DependencyInjection/Futurum.Microsoft.Extensions.DependencyInjection.csproj @@ -9,7 +9,7 @@ Futurum.Microsoft.Extensions.DependencyInjection dotnet-logo.png - A dotnet library, that allows Microsoft.Extensions.DependencyInjection to work with Futurum.Core. It also add modules and startables. + A dotnet library, that allows Microsoft.Extensions.DependencyInjection to work with Futurum.Core. It also adds support for modules and startables. https://www.futurum.dev/projects/dotnet-futurum.html https://github.com/futurum-dev/dotnet.futurum.microsoft.extensions.dependencyinjection MIT @@ -28,7 +28,7 @@ - + diff --git a/test/Futurum.Microsoft.Extensions.DependencyInjection.Tests/Futurum.Microsoft.Extensions.DependencyInjection.Tests.csproj b/test/Futurum.Microsoft.Extensions.DependencyInjection.Tests/Futurum.Microsoft.Extensions.DependencyInjection.Tests.csproj index 3125512..a9d406e 100644 --- a/test/Futurum.Microsoft.Extensions.DependencyInjection.Tests/Futurum.Microsoft.Extensions.DependencyInjection.Tests.csproj +++ b/test/Futurum.Microsoft.Extensions.DependencyInjection.Tests/Futurum.Microsoft.Extensions.DependencyInjection.Tests.csproj @@ -7,9 +7,9 @@ - + - + all