-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathInfrastructureServiceCollectionExtensions.cs
More file actions
36 lines (32 loc) · 1.69 KB
/
InfrastructureServiceCollectionExtensions.cs
File metadata and controls
36 lines (32 loc) · 1.69 KB
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
using Keeptrack.Infrastructure.MongoDb.Repositories;
using Microsoft.Extensions.DependencyInjection.Extensions;
using MongoDB.Bson.Serialization.Conventions;
using MongoDB.Driver;
namespace Keeptrack.WebApi.DependencyInjection;
internal static class InfrastructureServiceCollectionExtensions
{
internal static void AddMongoDbInfrastructure(this IServiceCollection services, AppConfiguration configuration)
{
services.AddSingleton<IMongoClient>(sp =>
{
var pack = new ConventionPack
{
new CamelCaseElementNameConvention(),
new EnumRepresentationConvention(BsonType.String),
new IgnoreExtraElementsConvention(true),
new IgnoreIfNullConvention(true)
};
ConventionRegistry.Register("Conventions", pack, t => true);
return new MongoClient(configuration.ConnectionString);
});
services.AddSingleton<IMongoDatabase>(sp =>
sp.GetRequiredService<IMongoClient>().GetDatabase(configuration.DatabaseName));
services.TryAddScoped<Domain.Repositories.IBookRepository, BookRepository>();
services.TryAddScoped<Domain.Repositories.ICarRepository, CarRepository>();
services.TryAddScoped<Domain.Repositories.ICarHistoryRepository, CarHistoryRepository>();
services.TryAddScoped<Domain.Repositories.IMovieRepository, MovieRepository>();
services.TryAddScoped<Domain.Repositories.IMusicAlbumRepository, MusicAlbumRepository>();
services.TryAddScoped<Domain.Repositories.ITvShowRepository, TvShowRepository>();
services.TryAddScoped<Domain.Repositories.IVideoGameRepository, VideoGameRepository>();
}
}