66using Microsoft . Extensions . DependencyInjection ;
77using Microsoft . Extensions . DependencyInjection . Extensions ;
88using Microsoft . Extensions . Options ;
9+
910using Orleans ;
1011using Orleans . ApplicationParts ;
1112using Orleans . CodeGeneration ;
12- using Orleans . Configuration . Overrides ;
1313using Orleans . Hosting ;
1414using Orleans . Runtime ;
1515
1616namespace Orleankka . Cluster
1717{
1818 using Client ;
19- using Utility ;
2019
21- public sealed class OrleankkaClusterOptions
20+ public static class SiloHostBuilderExtension
2221 {
23- IActorRefMiddleware actorRefMiddleware ;
24- IActorMiddleware actorMiddleware ;
25-
26- /// <summary>
27- /// Registers global actor middleware (interceptor).
28- /// </summary>
29- /// <param name="middleware">The middleware.</param>
30- public OrleankkaClusterOptions ActorMiddleware ( IActorMiddleware middleware )
31- {
32- actorMiddleware = middleware ;
33- return this ;
34- }
35-
36- /// <summary>
37- /// Registers global cluster-wide <see cref="ActorRef"/> middleware (interceptor)
38- /// </summary>
39- /// <param name="middleware">The middleware.</param>
40- public OrleankkaClusterOptions ActorRefMiddleware ( IActorRefMiddleware middleware )
41- {
42- Requires . NotNull ( middleware , nameof ( middleware ) ) ;
22+ public static ISiloHostBuilder UseOrleankka ( this ISiloHostBuilder builder ) =>
23+ builder . ConfigureServices ( services => UseOrleankka ( builder . GetApplicationPartManager ( ) , services ) ) ;
4324
44- if ( actorRefMiddleware != null )
45- throw new InvalidOperationException ( "ActorRef middleware for cluster has been already registered" ) ;
25+ public static ISiloBuilder UseOrleankka ( this ISiloBuilder builder ) =>
26+ builder . ConfigureServices ( services => UseOrleankka ( builder . GetApplicationPartManager ( ) , services ) ) ;
4627
47- actorRefMiddleware = middleware ;
48- return this ;
28+ static void UseOrleankka ( IApplicationPartManager apm , IServiceCollection services )
29+ {
30+ Configure ( apm , services ) ;
31+ apm . AddApplicationPart ( typeof ( IClientEndpoint ) . Assembly )
32+ . WithCodeGeneration ( ) ;
4933 }
50-
51- internal void Configure ( IApplicationPartManager apm , IServiceCollection services )
34+
35+ static void Configure ( IApplicationPartManager apm , IServiceCollection services )
5236 {
5337 var assemblies = apm . ApplicationParts
5438 . OfType < AssemblyPart > ( ) . Select ( x => x . Assembly )
5539 . ToArray ( ) ;
5640
57- services . AddSingleton ( sp => new ClusterActorSystem ( assemblies , sp , actorRefMiddleware , actorMiddleware ) ) ;
58- services . AddSingleton ( sp => new ClientActorSystem ( assemblies , sp , actorRefMiddleware ) ) ;
41+ services . AddSingleton ( sp => new ClusterActorSystem ( assemblies , sp ) ) ;
42+ services . AddSingleton ( sp => new ClientActorSystem ( assemblies , sp ) ) ;
5943
6044 services . AddSingleton < IActorSystem > ( sp => sp . GetService < ClusterActorSystem > ( ) ) ;
6145 services . AddSingleton < IClientActorSystem > ( sp => sp . GetService < ClientActorSystem > ( ) ) ;
@@ -70,7 +54,7 @@ internal void Configure(IApplicationPartManager apm, IServiceCollection services
7054 services . AddOptions < DispatcherOptions > ( ) ;
7155 }
7256
73- DispatcherRegistry BuildDispatcherRegistry ( IServiceProvider services , IEnumerable < Assembly > assemblies )
57+ static DispatcherRegistry BuildDispatcherRegistry ( IServiceProvider services , IEnumerable < Assembly > assemblies )
7458 {
7559 var dispatchActors = assemblies . SelectMany ( x => x . GetTypes ( ) )
7660 . Where ( x => typeof ( DispatchActorGrain ) . IsAssignableFrom ( x ) && ! x . IsAbstract ) ;
@@ -83,33 +67,6 @@ DispatcherRegistry BuildDispatcherRegistry(IServiceProvider services, IEnumerabl
8367
8468 return dispatcherRegistry ;
8569 }
86- }
87-
88- public static class SiloHostBuilderExtension
89- {
90- public static ISiloHostBuilder UseOrleankka ( this ISiloHostBuilder builder ) =>
91- UseOrleankka ( builder , new OrleankkaClusterOptions ( ) ) ;
92-
93- public static ISiloHostBuilder UseOrleankka ( this ISiloHostBuilder builder , Func < OrleankkaClusterOptions , OrleankkaClusterOptions > configure ) =>
94- UseOrleankka ( builder , configure ( new OrleankkaClusterOptions ( ) ) ) ;
95-
96- public static ISiloHostBuilder UseOrleankka ( this ISiloHostBuilder builder , OrleankkaClusterOptions cfg ) =>
97- builder . ConfigureServices ( services => UseOrleankka ( builder . GetApplicationPartManager ( ) , services , cfg ) ) ;
98-
99- public static ISiloBuilder UseOrleankka ( this ISiloBuilder builder ) =>
100- UseOrleankka ( builder , new OrleankkaClusterOptions ( ) ) ;
101-
102- public static ISiloBuilder UseOrleankka ( this ISiloBuilder builder , Func < OrleankkaClusterOptions , OrleankkaClusterOptions > configure ) =>
103- UseOrleankka ( builder , configure ( new OrleankkaClusterOptions ( ) ) ) ;
104-
105- public static ISiloBuilder UseOrleankka ( this ISiloBuilder builder , OrleankkaClusterOptions cfg ) =>
106- builder . ConfigureServices ( services => UseOrleankka ( builder . GetApplicationPartManager ( ) , services , cfg ) ) ;
107-
108- static void UseOrleankka ( IApplicationPartManager apm , IServiceCollection services , OrleankkaClusterOptions cfg )
109- {
110- cfg . Configure ( apm , services ) ;
111- apm . AddApplicationPart ( typeof ( IClientEndpoint ) . Assembly ) . WithCodeGeneration ( ) ;
112- }
11370
11471 public static IClientActorSystem ActorSystem ( this ISiloHost host ) => host . Services . GetRequiredService < IClientActorSystem > ( ) ;
11572 }
0 commit comments