42 lines
1.8 KiB
C#
42 lines
1.8 KiB
C#
using IM.Application.Abstractions;
|
|
using IM.Commons;
|
|
using IM.Infrastructure.Efcore;
|
|
using IM.Protocols.Grpc.Contact;
|
|
using IM.Protocols.Grpc.User;
|
|
using MessageService.Infrastructure;
|
|
using MessageService.WebApi.Application;
|
|
using MessageService.WebApi.Application.Conversation;
|
|
using MessageService.WebApi.Application.IntegrationServices;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace MessageService.WebApi
|
|
{
|
|
public class ModuleInit : IModuleInitializer
|
|
{
|
|
public void Initialize(IServiceCollection services)
|
|
{
|
|
services.AddScoped<Application.Message.MessageService>();
|
|
services.AddScoped<IUnitOfWork, EfUnitOfWork<MessageDbContext>>();
|
|
services.AddScoped<ConversationService>();
|
|
services.AddScoped<SquenceService>();
|
|
services.AddScoped<IContactIntegrationService, ContactIntegrationService>();
|
|
services.AddHttpClient<IGroupMemberIntegrationService, GroupMemberIntegrationService>((sp, c) =>
|
|
{
|
|
var configuration = sp.GetRequiredService<IConfiguration>();
|
|
c.BaseAddress = new Uri(configuration["InternalServices:GroupServiceBaseUrl"]
|
|
?? "http://im-group-service:8080/");
|
|
var internalApiKey = configuration["InternalApiKey"];
|
|
if (!string.IsNullOrWhiteSpace(internalApiKey))
|
|
{
|
|
c.DefaultRequestHeaders.Add("X-Internal-Api-Key", internalApiKey);
|
|
}
|
|
});
|
|
services.AddGrpcClient<ContactInternal.ContactInternalClient>((sp, o) =>
|
|
{
|
|
var options = sp.GetRequiredService<IOptionsMonitor<GrpcOptions>>();
|
|
o.Address = new Uri(options.CurrentValue.ContactServiceUrl);
|
|
});
|
|
}
|
|
}
|
|
}
|