Share registrations using Modules
mainModules allow you to group service registrations into reusable sets.
- Create an interface and decorate it with
[ServiceProviderModule]. - Add service registrations to the interface using attributes.
- Use the
[Import]attribute on your main[ServiceProvider]to include the module's services.
[ServiceProviderModule]
[Singleton(typeof(IService), typeof(ServiceImplementation))]
public interface IMyModule
{
}
[ServiceProvider]
[Import(typeof(IMyModule))]
internal partial class MyServiceProvider
{
}
MyServiceProvider c = new MyServiceProvider();
IService service = c.GetService<IEnumerable<IService>>();