Serviced is a simple lightweight library that handles service registrations for you.
This code was originally written by Georgi Stoyanov and forked for the RoverCore project. Many thanks to Georgi for offering his repository under the MIT license as we are doing with all RoverCore projects as well. Check out his original project here
// Register ( how ironic ) Serviced in your Startup.cs
services.AddServiced(typeof(Startup).Assembly);Pass as parameter the assemblies where your services are located. You can pass multiple assemblies or a single one.
There are 3 major interfaces
- ITransient
- IScoped
- ISingleton
All of them have generic and non-generic version.
Example: Lets say you want to register a service named "HomeService" with an interface "IHomeService" as transient service.
class HomeService: IHomeService, ITransient<IHomeService>The above interface basically saves you from this syntax in Startup.cs
services.AddTransient<IHomeService,HomeService>();Another example is, lets say you want to register "HomeService" without an interface. Simply inherit the ITransient interface.
class HomeService: ITransientBelow is the Startup.cs equivalent.
services.AddTransient<HomeService>();