-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServiceCollectionExtensions.cs
39 lines (31 loc) · 1.3 KB
/
ServiceCollectionExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
namespace MovieQuotes.UI.Extensions;
using Avalonia.Controls;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using MovieQuotes.Application.Operations.Commands;
using MovieQuotes.Infrastructure;
using MovieQuotes.UI.Services;
using MovieQuotes.UI.ViewModels;
using System.Linq;
using System.Reflection;
public static class ServiceCollectionExtensions
{
public static void AddCommonServices(this IServiceCollection Services, Window window)
{
Services.AddSingleton<IFilesService>(x => new FilesService(window));
Services.AddSingleton<NavigationService>();
var viewModelsTypes = typeof(ViewModelBase).Assembly.GetTypes()
.Where(t => t.IsAssignableTo(typeof(ViewModelBase)))
.Where(t => !t.IsAbstract);
foreach (var type in viewModelsTypes)
{
Services.AddTransient(type);
}
Services.AddLogging();
Services.AddAutoMapper(typeof(MainWindowViewModel));
// add database
var cs = "Server=localhost;Database=MovieQuotesDb;Trusted_Connection=True;TrustServerCertificate=True";
Services.AddDbContext<MovieQuotesDbContext>(op => op.UseSqlServer(cs));
Services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblies(typeof(CreateMovieCommand).Assembly));
}
}