### Console Output Example of Registered Dependency Injection Services Source: https://github.com/yozian/yozian.dependencyinjectionplus/blob/master/README.md This text snippet provides an example of the console output generated by the DependencyInjectionSample project. It displays a summary of registered services, categorizing them by their lifecycle (Transient, Scoped) and showing the concrete type mapped to its service types. ```text Register Transient Services , Total: 1 [ConcretType : SerivceTypes] (1) DemoService: DemoService Register Scoped Services , Total: 1 [ConcretType : SerivceTypes] (1) WorkService: WorkService, IWorker ``` -------------------------------- ### Define Service Lifecycles with Transient, Scoped, and Singleton Attributes Source: https://github.com/yozian/yozian.dependencyinjectionplus/blob/master/README.md This example illustrates how to easily assign service lifecycles (Transient, Scoped, or Singleton) by decorating a class with the corresponding attributes provided by the Dependency Injection Plus library. Each attribute ensures the service is registered with the specified lifetime. ```csharp [TransientService] public class DemoService { public void ShowTime() { Console.WriteLine(DateTime.Now.ToString()); } } [ScopedService] public class DemoService { public void ShowTime() { Console.WriteLine(DateTime.Now.ToString()); } } [SingletonService] public class DemoService { public void ShowTime() { Console.WriteLine(DateTime.Now.ToString()); } } ``` -------------------------------- ### Register Services in .NET Core with Dependency Injection Plus Source: https://github.com/yozian/yozian.dependencyinjectionplus/blob/master/README.md This snippet demonstrates various methods to register services using the `RegisterServices` extension on `IServiceCollection`. It covers global registration, assembly-specific registration by name, conditional registration based on type name, and registration for a specific assembly object. ```csharp // sample for .net core public void ConfigureServices(IServiceCollection services) { // just choose one of them to fit your scenario // 1. register services services.RegisterServices(); // 2. register services only in those assmbly name start with "DependencyInjectionSample" services.RegisterServices("DependencyInjectionSample"); // 3. register services and has some condition services.RegisterServices("", type => { return type.Name.Contains("Service"); }); // 4. regiter services for specify assembly services.RegisterServicesOfAssembly(new { }.GetType().Assembly); } ``` -------------------------------- ### Register Services Implementing Multiple Interfaces via Attributes Source: https://github.com/yozian/yozian.dependencyinjectionplus/blob/master/README.md This code shows how to register a service that implements one or more interfaces. By specifying the interface types within the `ScopedService` attribute, the `WorkService` is automatically registered for both `IWorker` and `IDriver` interfaces. ```csharp [ScopedService(typeof(IWorker), typeof(IDriver))] public class WorkService : IWorker, IDriver { public void DoWork() { Console.WriteLine(nameof(this.DoWork)); } public void Drive() => throw new NotImplementedException(); } ``` -------------------------------- ### Conditionally Register Services for Specific ASP.NET Core Environments Source: https://github.com/yozian/yozian.dependencyinjectionplus/blob/master/README.md This snippet demonstrates how to restrict service registration to specific ASP.NET Core environments, such as 'Development' or 'Staging'. By providing a comma-separated list of environment names to the `ScopedService` attribute, the service is only registered when the `ASPNETCORE_ENVIRONMENT` variable matches. ```csharp [ScopedService("Developement,Staging")] public class WorkService : IWorker, IDriver { public void DoWork() { Console.WriteLine(nameof(this.DoWork)); } public void Drive() => throw new NotImplementedException(); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.