-
-
Save christiannagel/b2c77869d3f492dc583c77467560dc3c to your computer and use it in GitHub Desktop.
Register services in the Microsoft.Extensions.DependencyInjection container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AppServices | |
{ | |
private AppServices() | |
{ | |
var services = new ServiceCollection(); | |
// view-models | |
services.AddTransient<BooksViewModel>(); | |
// services | |
services.AddTransient<IItemsService<Book>, BooksService>(); | |
services.AddTransient<IShowProgressInfo, ShowProgressInfo>(); | |
// stateful services | |
services.AddScoped<IItemToViewModelMap<Book, BookItemViewModel>, BookToBookItemViewModelMap>(); | |
services.AddScoped<ISharedItems<Book>, SharedItems<Book>>(); | |
services.AddScoped<IRepository<Book, int>, BooksSampleRepository>(); | |
// logging configuration | |
services.AddLogging(builder => | |
{ | |
#if DEBUG | |
builder.AddDebug().SetMinimumLevel(LogLevel.Trace); | |
#endif | |
}); | |
ServiceProvider = services.BuildServiceProvider(); | |
} | |
public IServiceProvider ServiceProvider { get; } | |
private static AppServices _instance; | |
private static readonly object _instanceLock = new object(); | |
private static AppServices GetInstance() | |
{ | |
lock (_instanceLock) | |
{ | |
return _instance ?? (_instance = new AppServices()); | |
} | |
} | |
public static AppServices Instance => _instance ?? GetInstance(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment