Using Dependency Injection with Scrutor in .NET MAUI
Here's how you can use Scrutor in a .NET MAUI application:
1. Install the Scrutor Package: you can do this using the Nuget Package Manager Console or the Visual Studio Package Manager.
2. Create service lifetime Interfaces for registration:
3. Register Services:
Before registering Services, we have to create a Asembly helper to get all Asemblies:
Then we register services in MauiProgram.cs:
4. Using the Registered Services:
You can change ITransientDependency to IScopedDependency or ISingletonDependency. It depends on your service lifetimes and you can also register pages, viewmodels,... with this.
Hence, to use Dependency Injection you just create a class inherits one of three service lifetimes above, Scrutor will automatically register your service for you.
You can visit my repos on GitHub for more details.