-
Notifications
You must be signed in to change notification settings - Fork 1
/
ServiceCollectionExtensionsTemplate.sbntxt
40 lines (34 loc) · 1.35 KB
/
ServiceCollectionExtensionsTemplate.sbntxt
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
40
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Nyris.Crdt.Distributed.Extensions;
using ProtoBuf.Grpc.Server;
namespace Nyris.Crdt.Distributed
{
internal static class ServiceCollectionExtensions
{
public static ManagedCrdtsServicesBuilder AddManagedCrdts<TContext>(this IServiceCollection services)
where TContext : ManagedCrdtContext
{
ProtoBuf.Meta.RuntimeTypeModel.Default.IncludeDateTimeKind = true;
services.AddCodeFirstGrpc(options =>
{
options.EnableDetailedErrors = true;
});
services.AddInternals<IManagedCrdtService>();
services.AddSingleton<TContext>();
services.AddSingleton<ManagedCrdtContext, TContext>(sp => sp.GetRequiredService<TContext>());
{{~ for type in DtoInfos ~}}
{{~ for crdtInfo in type.CrdtInfos ~}}
services.AddConnectionServices<{{ crdtInfo.TypeName }}, {{ crdtInfo.AllArgumentsString }}>();
{{~ end ~}}
{{~ end ~}}
return new ManagedCrdtsServicesBuilder(services);
}
public static IEndpointRouteBuilder MapManagedCrdtService(this IEndpointRouteBuilder endpoints)
{
endpoints.MapGrpcService<ManagedCrdtService>();
return endpoints;
}
}
}