public ServiceClient Construct(ClusteringConfiguration clusteringConfiguration) { if (clusteringConfiguration.ClusteringRole == ClusteringRole.HostOnly && !IPAddress.IsLoopback(clusteringConfiguration.Address)) { throw new InvalidOperationException("It is impossible host a Dargon Service cluster located at a remote address!"); } LocalServiceContainer localServiceContainer = new LocalServiceContainerImpl(collectionFactory); ClusteringPhaseManager clusteringPhaseManager = new ClusteringPhaseManagerImpl(); PortableObjectBoxConverter portableObjectBoxConverter = new PortableObjectBoxConverter(streamFactory, pofSerializer); HostSessionFactory hostSessionFactory = new HostSessionFactoryImpl(threadingProxy, collectionFactory, pofSerializer, pofStreamsFactory, portableObjectBoxConverter); ClusteringPhaseFactory clusteringPhaseFactory = new ClusteringPhaseFactoryImpl(collectionFactory, threadingProxy, networkingProxy, pofStreamsFactory, hostSessionFactory, clusteringConfiguration, portableObjectBoxConverter, clusteringPhaseManager); ClusteringPhase initialClusteringPhase = clusteringPhaseFactory.CreateIndeterminatePhase(localServiceContainer); clusteringPhaseManager.Transition(initialClusteringPhase); RemoteServiceInvocationValidatorFactory validatorFactory = new RemoteServiceInvocationValidatorFactoryImpl(collectionFactory); RemoteServiceProxyFactory remoteServiceProxyFactory = new RemoteServiceProxyFactoryImpl(proxyGenerator, portableObjectBoxConverter, validatorFactory, clusteringPhaseManager); InvokableServiceContextFactory invokableServiceContextFactory = new InvokableServiceContextFactoryImpl(collectionFactory, portableObjectBoxConverter); IConcurrentDictionary <Guid, InvokableServiceContext> serviceContextsById = new ConcurrentDictionary <Guid, InvokableServiceContext>(); LocalServiceRegistry localServiceRegistry = new LocalServiceRegistryImpl(localServiceContainer, clusteringPhaseManager, invokableServiceContextFactory, serviceContextsById); IConcurrentDictionary <Type, object> serviceProxiesByInterface = new ConcurrentDictionary <Type, object>(); RemoteServiceProxyContainer remoteServiceProxyContainer = new RemoteServiceProxyContainerImpl(remoteServiceProxyFactory, serviceProxiesByInterface); return(new ServiceClientProxyImpl(localServiceRegistry, remoteServiceProxyContainer)); }
private ServiceClientFactoryImpl CreateServiceClientFactory(params PofContext[] pofContexts) { var proxyGenerator = new ProxyGenerator(); ICollectionFactory collectionFactory = new CollectionFactory(); IThreadingFactory threadingFactory = new ThreadingFactory(); ISynchronizationFactory synchronizationFactory = new SynchronizationFactory(); IThreadingProxy threadingProxy = new ThreadingProxy(threadingFactory, synchronizationFactory); IDnsProxy dnsProxy = new DnsProxy(); ITcpEndPointFactory tcpEndPointFactory = new TcpEndPointFactory(dnsProxy); IStreamFactory streamFactory = new StreamFactory(); INetworkingInternalFactory networkingInternalFactory = new NetworkingInternalFactory(threadingProxy, streamFactory); ISocketFactory socketFactory = new SocketFactory(tcpEndPointFactory, networkingInternalFactory); INetworkingProxy networkingProxy = new NetworkingProxy(socketFactory, tcpEndPointFactory); PofContext pofContext = new DspPofContext(); pofContexts.ForEach(pofContext.MergeContext); IPofSerializer pofSerializer = new PofSerializer(pofContext); PofStreamsFactory pofStreamsFactory = new PofStreamsFactoryImpl(threadingProxy, streamFactory, pofSerializer); PortableObjectBoxConverter portableObjectBoxConverter = new PortableObjectBoxConverter(streamFactory, pofSerializer); InvokableServiceContextFactory invokableServiceContextFactory = new InvokableServiceContextFactoryImpl(collectionFactory, portableObjectBoxConverter); return(new ServiceClientFactoryImpl(proxyGenerator, streamFactory, collectionFactory, threadingProxy, networkingProxy, pofSerializer, pofStreamsFactory)); }