From 8b54ba04d53ad3c90c13a74763ce1930627d7ea8 Mon Sep 17 00:00:00 2001 From: Alexandru Macocian Date: Fri, 12 Nov 2021 17:16:43 +0100 Subject: [PATCH] Fix readme link --- README.md | 27 ++++++++++++++- Slim/README.md | 89 ------------------------------------------------ Slim/Slim.csproj | 1 + 3 files changed, 27 insertions(+), 90 deletions(-) delete mode 100644 Slim/README.md diff --git a/README.md b/README.md index e5bb019..f468dad 100644 --- a/README.md +++ b/README.md @@ -19,10 +19,15 @@ To manage the lifetime of the objects, use ``` serviceManager.RegisterSingleton Can register a services for all interaces it implements: ```c# -serviceManager.RegisterSingleton(); +serviceManager.RegisterSingleton(registerAllInterfaces: true); serviceManager.GetService(); serviceManager.GetService(); ``` +Otherwise, calling +```c# +serviceManager.RegisterSingleton(); +``` +Will only register Service1 as Service1. Supports both generics or arguments as types: ```c# @@ -62,3 +67,23 @@ To create a scope, call the following method and use the new instance of scoped ```c# serviceManager.CreateScope(); ``` + +By default, the returned scope manager will be readonly. This means, calling +```c# +scopedServiceManager.RegisterService(); +``` +will throw an InvalidOperationException. + +To override the functionality from above, set the `AllowScopedManagerModifications` property to true in the original service manager before creating the scoped service manager +```c# +serviceManager.AllowScopedManagerModifications = true; +var scopedServiceManager = serviceManager.CreateScope(); +scopedServiceManager.RegisterService(); +``` +This way, no exception is thrown. + +To retrieve all services of a certain type from the service manager, use +```c# +serviceManager.GetServicesOfType(); +``` +This will return an `IEnumerable` with all the services which implement the `ISharedInterface`. \ No newline at end of file diff --git a/Slim/README.md b/Slim/README.md deleted file mode 100644 index f468dad..0000000 --- a/Slim/README.md +++ /dev/null @@ -1,89 +0,0 @@ -# Slim -## Service lifetime manager and dependency injection framework - -Uses lazy approach and only implements objects when called. - -Supports multiple Register calls without needing to rebuild. - -Supports scoped lifetime of services. - -To use, simply create and register types: -```c# -var serviceManager = new ServiceManager(); -serviceManager.RegisterSingleton(); -serviceManager.RegisterSingleton(sp => new Service2(sp.GetService()); -serviceManager.GetService(); -``` - -To manage the lifetime of the objects, use ``` serviceManager.RegisterSingleton ```, ``` serviceManager.RegisterTransient ``` or ``` serviceManager.RegisterScoped ```. - -Can register a services for all interaces it implements: -```c# -serviceManager.RegisterSingleton(registerAllInterfaces: true); -serviceManager.GetService(); -serviceManager.GetService(); -``` -Otherwise, calling -```c# -serviceManager.RegisterSingleton(); -``` -Will only register Service1 as Service1. - -Supports both generics or arguments as types: -```c# -serviceManager.RegisterTransient(); -serviceManager.RegisterTransient(typeof(IService2), typeof(Service2)); -``` - -Can register current service manager as a valid dependency: -```c# -serviceManager.RegisterServiceManager(); -``` - -Can handle multiple types of exceptions: -```c# -serviceManager.HandleException((sp, ex) => DoSomething1(ex)); -serviceManager.HandleException((sp, ex) => DoSomething2(ex)); -serviceManager.HandleException((sp, ex) => DoSomething3(ex)); -``` - -In case of reinitialization, call: -```c# -serviceManager.Clear(); -``` -``` serviceManager.Clear ``` calls ``` IDisposable.Dispose ``` on singletons that implement ``` IDisposable ```. - -To build all singletons currently registered, call: -```c# -serviceManager.BuildSingletons(); -``` - -`IDependencyResolver` interface to implement manual resolvers for special cases. Register on the `IServiceManager` using: -```c# -serviceManager.RegisterResolver(new SomeDependencyResolver()); -``` - -To create a scope, call the following method and use the new instance of scoped IServiceProvider. -```c# -serviceManager.CreateScope(); -``` - -By default, the returned scope manager will be readonly. This means, calling -```c# -scopedServiceManager.RegisterService(); -``` -will throw an InvalidOperationException. - -To override the functionality from above, set the `AllowScopedManagerModifications` property to true in the original service manager before creating the scoped service manager -```c# -serviceManager.AllowScopedManagerModifications = true; -var scopedServiceManager = serviceManager.CreateScope(); -scopedServiceManager.RegisterService(); -``` -This way, no exception is thrown. - -To retrieve all services of a certain type from the service manager, use -```c# -serviceManager.GetServicesOfType(); -``` -This will return an `IEnumerable` with all the services which implement the `ISharedInterface`. \ No newline at end of file diff --git a/Slim/Slim.csproj b/Slim/Slim.csproj index f8a296d..93be5a6 100644 --- a/Slim/Slim.csproj +++ b/Slim/Slim.csproj @@ -26,6 +26,7 @@ True +