50 lines
2.3 KiB
C#
50 lines
2.3 KiB
C#
using Knot.Contracts.Messaging.Application.Abstractions;
|
|
using Knot.Contracts.Messaging.Domain;
|
|
using Knot.Modules.Conversations.Application.Abstractions;
|
|
using Knot.Modules.Conversations.Domain;
|
|
using Knot.Modules.Conversations.Infrastructure.Persistence;
|
|
using Knot.Modules.Conversations.Infrastructure.Persistence.Mongo;
|
|
using Knot.Shared.Kernel;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Knot.Modules.Conversations;
|
|
|
|
public static class DependencyInjection
|
|
{
|
|
public static IServiceCollection AddConversationsModule(
|
|
this IServiceCollection services,
|
|
IConfiguration configuration)
|
|
{
|
|
string connectionString = configuration.GetConnectionString("DefaultConnection")!;
|
|
|
|
services.AddDbContext<ChatsDbContext>(options =>
|
|
options.UseNpgsql(connectionString));
|
|
|
|
// MongoDB Setup for Messages
|
|
ConversationsMongoDbMapConfigurator.Configure();
|
|
|
|
var mongoConnectionString = configuration.GetConnectionString("MongoConnection") ?? "mongodb://localhost:27017";
|
|
|
|
// Registration
|
|
services.AddScoped<IChatsUnitOfWork>(sp => sp.GetRequiredService<ChatsDbContext>());
|
|
services.AddScoped<IChatRepository, ChatRepository>();
|
|
services.AddScoped<IFolderRepository, FolderRepository>();
|
|
services.AddScoped<IUserChatSettingsRepository, UserChatSettingsRepository>();
|
|
services.AddScoped<IUserFolderSettingsRepository, UserFolderSettingsRepository>();
|
|
|
|
// Messaging Repository - registered in Messaging module
|
|
// services.AddScoped<IMessageRepository, MessageRepository>();
|
|
|
|
// MediatR
|
|
services.AddMediatR(config =>
|
|
config.RegisterServicesFromAssembly(typeof(DependencyInjection).Assembly));
|
|
|
|
services.AddScoped<Knot.Contracts.Messaging.Application.Abstractions.IChatAccessProvider, Knot.Modules.Conversations.Infrastructure.Services.ChatAccessProvider>();
|
|
services.AddScoped<Knot.Contracts.Messaging.Application.Abstractions.IMessageNotifier, Knot.Modules.Conversations.Infrastructure.SignalR.MessageNotifier>();
|
|
services.AddScoped<IUserStatusService, Knot.Modules.Conversations.Infrastructure.Services.UserStatusService>();
|
|
return services;
|
|
}
|
|
}
|