public async Task<IRyuContainer> CreateAsync(IReadOnlySet<ITransportFactory> transportFactories, Guid? forceId = null) { var container = root.CreateChildContainer(); var proxyGenerator = container.GetOrDefault<ProxyGenerator>() ?? new ProxyGenerator(); var shutdownCancellationTokenSource = new CancellationTokenSource(); // Auditing Subsystem var auditService = new AuditService(shutdownCancellationTokenSource.Token); auditService.Initialize(); // management tier containers var mobContextContainer = new MobContextContainer(); var mobContextFactory = new MobContextFactory(auditService); var mobOperations = new MobOperations(mobContextFactory, mobContextContainer); // Other Courier Stuff var identity = Identity.Create(forceId); var routingTable = new RoutingTable(); var peerDiscoveryEventBus = new AsyncBus<PeerDiscoveryEvent>(); var peerTable = new PeerTable(container, (table, peerId) => new PeerContext(table, peerId, peerDiscoveryEventBus)); var inboundMessageRouter = new InboundMessageRouter(); var inboundMessageDispatcher = new InboundMessageDispatcher(identity, peerTable, inboundMessageRouter); var transports = new ConcurrentSet<ITransport>(); foreach (var transportFactory in transportFactories) { var transport = await transportFactory.CreateAsync(mobOperations, identity, routingTable, peerTable, inboundMessageDispatcher, auditService).ConfigureAwait(false); transports.TryAdd(transport); } var messenger = new Messenger(identity, transports, routingTable); container.Set(identity); container.Set(routingTable); container.Set(peerTable); container.Set(inboundMessageRouter); container.Set(messenger); //---------------------------------------------------------------------------------------- // Service Tier - Service Discovery, Remote Method Invocation //---------------------------------------------------------------------------------------- var localServiceRegistry = new LocalServiceRegistry(identity, messenger); var remoteServiceInvoker = new RemoteServiceInvoker(identity, messenger); var remoteServiceProxyContainer = new RemoteServiceProxyContainer(proxyGenerator, remoteServiceInvoker); inboundMessageRouter.RegisterHandler<RmiRequestDto>(localServiceRegistry.HandleInvocationRequestAsync); inboundMessageRouter.RegisterHandler<RmiResponseDto>(remoteServiceInvoker.HandleInvocationResponse); container.Set(localServiceRegistry); container.Set(remoteServiceProxyContainer); //---------------------------------------------------------------------------------------- // Management Tier - DMI - Services //---------------------------------------------------------------------------------------- var managementObjectService = new ManagementObjectService(mobContextContainer, mobOperations); localServiceRegistry.RegisterService<IManagementObjectService>(managementObjectService); container.Set(mobOperations); container.Set(managementObjectService); var facade = new CourierFacade(transports, container); container.Set(facade); return container; }
public static void RegisterService <TServiceInterface>(this LocalServiceRegistry localServiceRegistry, object service) { localServiceRegistry.RegisterService(typeof(TServiceInterface), service); }