示例#1
0
        //static async Task MainAsync(string[] args)
        //{



        //    var builder = new SiloHostBuilder()
        //        .ConfigureLogging(ConfigureLogging);



        //       .Configure<ClusterOptions>(options =>
        //       {
        //           // https://github.com/dotnet/orleans/issues/5696
        //           options.ClusterId = "0.0.1";
        //           options.ServiceId = serviceId;
        //       })
        //       //.


        //        // .UseConfiguration(LoadClusterConfiguration)
        //        .UseServiceProviderFactory(ConfigureServices)



        //    SiloHost = builder.Build();
        //    await StartAsync();
        //    //Console.WriteLine("Press Ctrl+C to terminate...");
        //    //Console.CancelKeyPress += (s, e) => _exitEvent.Set();

        //    //_exitEvent.WaitOne();

        //    //Console.WriteLine("Stopping...");
        //    //await SiloHost.StopAsync();
        //    //await SiloHost.Stopped;
        //    //Console.WriteLine("Stopped.");

        //}

        //private static ClusterConfiguration LoadClusterConfiguration()
        //{

        //    // var conString = Configuration["SqlServerConnextionString"];
        //    var cluster = new ClusterConfiguration();
        //    //cluster.StandardLoad();
        //    cluster.LoadFromFile("OrleansConfiguration.dev.xml");
        //    // cluster.Globals.SerializationProviders.Add(typeof(CslaOrleansSerialiser).GetTypeInfo());

        //    return cluster;


        //    //cluster.Globals.AdoInvariant = "System.Data.SqlClient";
        //    //cluster.Globals.ClusterId = "OrleansTest";

        //    //cluster.Globals.SeedNodes.Add(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 11111));
        //    //cluster.Globals.LivenessEnabled = true;
        //    //cluster.Globals.LivenessType = GlobalConfiguration.LivenessProviderType.SqlServer;

        //    //cluster.Defaults.ProxyGatewayEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 30000);
        //    //cluster.Defaults.HostNameOrIPAddress = "localhost";
        //    //cluster.Defaults.Port = 11111;

        //    //  cluster.Globals.DataConnectionStringForReminders = conString;
        //    //  cluster.Globals.AdoInvariantForReminders = "System.Data.SqlClient";

        //    //   cluster.AddAdoNetStorageProvider("AdoNetStorage", connectionString: conString, serializationFormat: AdoNetSerializationFormat.Json);
        //    //  cluster.AddAzureTableStorageProvider("AzureStore", "UseDevelopmentStorage=true");
        //}

        //private static async Task StartAsync()
        //{
        //    //  Serializers.RegisterAll(_siloHost.Services);
        //    await SiloHost.StartAsync();
        //}

        private static void ConfigureApplicationParts(IApplicationPartManager partManger)
        {
            partManger.AddApplicationPart(typeof(IOrleansGrainDataPortalServer).Assembly);
            partManger.AddApplicationPart(typeof(Program).Assembly);
            partManger.AddApplicationPart(typeof(Root).Assembly);
            partManger.AddApplicationPart(typeof(Csla.ApplicationContext).Assembly);
        }
        /// <summary>
        /// Adds the provided assembly to the builder.
        /// </summary>
        /// <param name="manager">The builder.</param>
        /// <param name="assembly">The assembly.</param>
        /// <returns>The builder with the additionally added assembly.</returns>
        public static IApplicationPartManager AddApplicationPart(this IApplicationPartManager manager, Assembly assembly)
        {
            if (manager == null)
            {
                throw new ArgumentNullException(nameof(manager));
            }

            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            // Always add the provided part, whether or not it contains generated code.
            manager.AddApplicationPart(new AssemblyPart(assembly));

            // Add all referenced application parts.
            foreach (var referencedAsm in GetApplicationPartAssemblies(assembly))
            {
                var part = new AssemblyPart(referencedAsm);
                if (manager.ApplicationParts.Contains(part))
                {
                    continue;
                }

                manager.AddApplicationPart(part);
            }

            return(manager);
        }
示例#3
0
 public static void AddClientApplicationParts(IApplicationPartManager parts)
 {
     // Add the base classes as well since they use IGrain
     parts.AddApplicationPart(typeof(ISpatialGrain).Assembly);
     // Add own grain interfaces
     parts.AddApplicationPart(typeof(IGridPartitionGrain).Assembly);
     parts.AddApplicationPart(typeof(IGridConfigurationGrain).Assembly);
 }
示例#4
0
        /// <summary>
        /// 装配Actor插件
        /// </summary>
        /// <param name="manager">IApplicationPartManager</param>
        /// <param name="filter">装配的Actor插件所在程序集统一采用"*.Plugin.dll"作为文件名后缀</param>
        public static void AddPluginPart(this IApplicationPartManager manager, string filter = "*.Plugin.dll")
        {
            if (String.IsNullOrEmpty(filter))
            {
                throw new ArgumentNullException(nameof(filter));
            }

            foreach (string fileName in Directory.GetFiles(AppRun.BaseDirectory, filter))
            {
                manager.AddApplicationPart(Assembly.LoadFrom(fileName)).WithReferences().WithCodeGeneration();
            }
        }
示例#5
0
        public static IApplicationPartManagerWithAssemblies AddFromAppDomainWithReferences(this IApplicationPartManager manager)
        {
            var assemblies = new List <Assembly>();

            foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                manager = manager.AddApplicationPart(asm).WithReferences();
                assemblies.Add(asm);
            }

            return(new ApplicationPartManagerWithAssemblies(manager, assemblies));
        }
示例#6
0
        /// <summary>
        /// Adds all assemblies referencing Orleans found in the provided assembly's <see cref="DependencyContext"/>.
        /// </summary>
        /// <param name="manager">The builder.</param>
        /// <returns>The builder with the additionally included assemblies.</returns>
        public static IApplicationPartManagerWithAssemblies AddFromDependencyContext(this IApplicationPartManager manager, Assembly entryAssembly)
        {
            entryAssembly = entryAssembly ?? Assembly.GetCallingAssembly();
            var dependencyContext = DependencyContext.Default;

            if (entryAssembly != null)
            {
                dependencyContext = DependencyContext.Load(entryAssembly) ?? DependencyContext.Default;
                manager           = manager.AddApplicationPart(entryAssembly);
            }

            if (dependencyContext == null)
            {
                return(new ApplicationPartManagerWithAssemblies(manager, Array.Empty <Assembly>()));
            }

            var assemblies = new List <Assembly>();

            foreach (var lib in dependencyContext.RuntimeLibraries)
            {
                if (!lib.Dependencies.Any(dep => dep.Name.Contains("Orleans")))
                {
                    continue;
                }

                try
                {
                    var asm = Assembly.Load(lib.Name);
                    manager.AddApplicationPart(new AssemblyPart(asm));
                    assemblies.Add(asm);
                }
                catch
                {
                    // Ignore any exceptions thrown during non-explicit assembly loading.
                }
            }

            return(new ApplicationPartManagerWithAssemblies(manager, assemblies));
        }
示例#7
0
        /// <summary>
        /// Adds the provided assembly to the builder.
        /// </summary>
        /// <param name="manager">The builder.</param>
        /// <param name="assembly">The assembly.</param>
        /// <returns>The builder with the additionally added assembly.</returns>
        public static IApplicationPartManagerWithAssemblies AddApplicationPart(this IApplicationPartManager manager, Assembly assembly)
        {
            if (manager == null)
            {
                throw new ArgumentNullException(nameof(manager));
            }

            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            return(new ApplicationPartManagerWithAssemblies(manager.AddApplicationPart(new AssemblyPart(assembly)), new[] { assembly }));
        }
示例#8
0
        /// <summary>
        /// Adds assemblies from the current <see cref="AppDomain"/> to the builder.
        /// </summary>
        /// <param name="manager">The builder.</param>
        /// <returns>The builder with the added assemblies.</returns>
        public static IApplicationPartManagerWithAssemblies AddFromAppDomain(this IApplicationPartManager manager)
        {
            if (manager == null)
            {
                throw new ArgumentNullException(nameof(manager));
            }

            var processedAssemblies = new HashSet <Assembly>(AppDomain.CurrentDomain.GetAssemblies());

            foreach (var assembly in processedAssemblies)
            {
                manager.AddApplicationPart(new AssemblyPart(assembly));
            }

            return(new ApplicationPartManagerWithAssemblies(manager, processedAssemblies));
        }
示例#9
0
        /// <summary>
        /// Adds assemblies from the current <see cref="AppDomain.BaseDirectory"/> to the builder.
        /// </summary>
        /// <param name="manager">The builder.</param>
        /// <returns>The builder with the additionally added assemblies.</returns>
        public static IApplicationPartManagerWithAssemblies AddFromApplicationBaseDirectory(this IApplicationPartManager manager)
        {
            var appDomainBase = AppDomain.CurrentDomain.BaseDirectory;

            if (string.IsNullOrWhiteSpace(appDomainBase) || !Directory.Exists(appDomainBase))
            {
                return(new ApplicationPartManagerWithAssemblies(manager, Enumerable.Empty <Assembly>()));
            }

            var dirs = new Dictionary <string, SearchOption> {
                [appDomainBase] = SearchOption.TopDirectoryOnly
            };

            AssemblyLoaderPathNameCriterion[] excludeCriteria =
            {
                AssemblyLoaderCriteria.ExcludeResourceAssemblies
            };

            AssemblyLoaderReflectionCriterion[] loadCriteria =
            {
                AssemblyLoaderReflectionCriterion.NewCriterion(ReferencesOrleansOrAbstractionsAssemblyPredicate)
            };

            var loadedAssemblies = AssemblyLoader.LoadAssemblies(dirs, excludeCriteria, loadCriteria, NullLogger.Instance);

            foreach (var assembly in loadedAssemblies)
            {
                manager.AddApplicationPart(new AssemblyPart(assembly));
            }

            return(new ApplicationPartManagerWithAssemblies(manager, loadedAssemblies));

            // Returns true if the provided assembly references the Orleans core or abstractions assembly.
            bool ReferencesOrleansOrAbstractionsAssemblyPredicate(Assembly assembly, out IEnumerable <string> complaints)
            {
                var referencesOrleans = assembly.GetReferencedAssemblies().Any(ReferencesOrleansOrAbstractions);

                complaints = referencesOrleans ? null : NoReferenceComplaint;
                return(referencesOrleans);

                bool ReferencesOrleansOrAbstractions(AssemblyName reference)
                {
                    return(string.Equals(reference.Name, CoreAssemblyName, StringComparison.OrdinalIgnoreCase) ||
                           string.Equals(reference.Name, AbstractionsAssemblyName, StringComparison.OrdinalIgnoreCase));
                }
            }
        }
示例#10
0
        public static IApplicationPartManagerWithAssemblies AddFromAssemblyLoadContext(this IApplicationPartManager manager, Assembly assembly = null)
        {
#if NETCOREAPP
            assembly ??= typeof(ApplicationPartManagerExtensions).Assembly;
            var assemblies = new HashSet <Assembly>();
            var context    = AssemblyLoadContext.GetLoadContext(assembly);
            foreach (var asm in context.Assemblies)
            {
                manager = manager.AddApplicationPart(asm);
                assemblies.Add(asm);
            }

            return(new ApplicationPartManagerWithAssemblies(manager, assemblies));
#else
            throw new PlatformNotSupportedException("AssemblyLoadContext is not supported on this platform");
#endif
        }
        /// <summary>
        /// Adds the provided assembly to the builder as a framework assembly.
        /// </summary>
        /// <param name="manager">The builder.</param>
        /// <param name="assembly">The assembly.</param>
        /// <returns>The builder with the additionally added assembly.</returns>
        public static IApplicationPartManager AddFrameworkPart(this IApplicationPartManager manager, Assembly assembly)
        {
            if (manager == null)
            {
                throw new ArgumentNullException(nameof(manager));
            }

            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            return(manager.AddApplicationPart(new AssemblyPart(assembly)
            {
                IsFrameworkAssembly = true
            }));
        }
        public static IApplicationPartManager AddFromAssemblyLoadContext(this IApplicationPartManager manager, Assembly assembly = null)
        {
            assembly ??= typeof(ApplicationPartManagerExtensions).Assembly;
            var assemblies = new HashSet <Assembly>();
            var context    = AssemblyLoadContext.GetLoadContext(assembly);

            foreach (var asm in context.Assemblies)
            {
                // Skip assemblies which have not had code generation executed against them and already-seen assemblies.
                if (!asm.IsDefined(typeof(ApplicationPartAttribute)) || !assemblies.Add(asm))
                {
                    continue;
                }

                manager.AddApplicationPart(asm);
            }

            return(manager);
        }
示例#13
0
 private static void AddClientApplicationParts(IApplicationPartManager parts)
 {
     GridConfigurationHelper.AddClientApplicationParts(parts);
     parts.AddApplicationPart(typeof(ISimpleGrain).Assembly);
 }
示例#14
0
 /// <summary>
 /// Utility method for add external assembly to SiloBuilder
 /// </summary>
 /// <param name="applicationPartManager"></param>
 /// <param name="assembly"></param>
 /// <returns></returns>
 public static IApplicationPartManagerWithAssemblies AddDynamicPart(this IApplicationPartManager applicationPartManager, Assembly assembly)
 {
     return(applicationPartManager.AddApplicationPart(assembly).WithReferences());
 }
示例#15
0
        internal static void AddDefaultServices(IApplicationPartManager applicationPartManager, IServiceCollection services)
        {
            services.AddOptions();

            services.AddTransient <IConfigurationValidator, EndpointOptionsValidator>();

            // Options logging
            services.TryAddSingleton(typeof(IOptionFormatter <>), typeof(DefaultOptionsFormatter <>));
            services.TryAddSingleton(typeof(IOptionFormatterResolver <>), typeof(DefaultOptionsFormatterResolver <>));

            // Register system services.
            services.TryAddSingleton <ILocalSiloDetails, LocalSiloDetails>();
            services.TryAddSingleton <ISiloHost, SiloWrapper>();
            services.TryAddTransient <ILifecycleSubject, LifecycleSubject>();
            services.TryAddSingleton <SiloLifecycleSubject>();
            services.TryAddFromExisting <ISiloLifecycleSubject, SiloLifecycleSubject>();
            services.TryAddFromExisting <ISiloLifecycle, SiloLifecycleSubject>();
            services.AddSingleton <SiloOptionsLogger>();
            services.AddFromExisting <ILifecycleParticipant <ISiloLifecycle>, SiloOptionsLogger>();
            services.PostConfigure <SiloMessagingOptions>(options =>
            {
                //
                // Assign environment specific defaults post configuration if user did not configured otherwise.
                //

                if (options.SiloSenderQueues == 0)
                {
                    options.SiloSenderQueues = Environment.ProcessorCount;
                }

                if (options.GatewaySenderQueues == 0)
                {
                    options.GatewaySenderQueues = Environment.ProcessorCount;
                }
            });
            services.TryAddSingleton <TelemetryManager>();
            services.TryAddFromExisting <ITelemetryProducer, TelemetryManager>();

            services.TryAddSingleton <IAppEnvironmentStatistics, AppEnvironmentStatistics>();
            services.TryAddSingleton <IHostEnvironmentStatistics, NoOpHostEnvironmentStatistics>();
            services.TryAddSingleton <SiloStatisticsManager>();
            services.TryAddFromExisting <IStatisticsManager, SiloStatisticsManager>();
            services.TryAddSingleton <ApplicationRequestsStatisticsGroup>();
            services.TryAddSingleton <StageAnalysisStatisticsGroup>();
            services.TryAddSingleton <SchedulerStatisticsGroup>();
            services.TryAddSingleton <SerializationStatisticsGroup>();
            services.TryAddSingleton <OverloadDetector>();

            // queue balancer contructing related
            services.TryAddTransient <IStreamQueueBalancer, ConsistentRingQueueBalancer>();

            services.TryAddSingleton <FallbackSystemTarget>();
            services.TryAddSingleton <LifecycleSchedulingSystemTarget>();

            services.AddLogging();
            services.TryAddSingleton <ITimerRegistry, TimerRegistry>();
            services.TryAddSingleton <IReminderRegistry, ReminderRegistry>();
            services.TryAddSingleton <GrainRuntime>();
            services.TryAddSingleton <IGrainRuntime, GrainRuntime>();
            services.TryAddSingleton <IGrainCancellationTokenRuntime, GrainCancellationTokenRuntime>();
            services.TryAddSingleton <OrleansTaskScheduler>();
            services.TryAddSingleton <GrainFactory>(sp => sp.GetService <InsideRuntimeClient>().ConcreteGrainFactory);
            services.TryAddFromExisting <IGrainFactory, GrainFactory>();
            services.TryAddFromExisting <IInternalGrainFactory, GrainFactory>();
            services.TryAddFromExisting <IGrainReferenceConverter, GrainFactory>();
            services.TryAddSingleton <IGrainReferenceRuntime, GrainReferenceRuntime>();
            services.TryAddSingleton <TypeMetadataCache>();
            services.TryAddSingleton <ActivationDirectory>();
            services.TryAddSingleton <ActivationCollector>();

            // Directory
            services.TryAddSingleton <LocalGrainDirectory>();
            services.TryAddFromExisting <ILocalGrainDirectory, LocalGrainDirectory>();
            services.AddSingleton <GrainLocator>();
            services.AddSingleton <GrainLocatorResolver>();
            services.AddSingleton <DhtGrainLocator>(sp => DhtGrainLocator.FromLocalGrainDirectory(sp.GetService <LocalGrainDirectory>()));
            services.AddSingleton <GrainDirectoryResolver>();
            services.AddSingleton <CachedGrainLocator>();
            services.AddFromExisting <ILifecycleParticipant <ISiloLifecycle>, CachedGrainLocator>();
            services.AddSingleton <ClientGrainLocator>();

            services.TryAddSingleton <GrainTypeManager>();
            services.TryAddSingleton <MessageCenter>();
            services.TryAddFromExisting <IMessageCenter, MessageCenter>();
            services.TryAddSingleton(FactoryUtility.Create <MessageCenter, Gateway>);
            services.TryAddSingleton <Dispatcher>(sp => sp.GetRequiredService <Catalog>().Dispatcher);
            services.TryAddSingleton <InsideRuntimeClient>();
            services.TryAddFromExisting <IRuntimeClient, InsideRuntimeClient>();
            services.TryAddFromExisting <ISiloRuntimeClient, InsideRuntimeClient>();
            services.AddFromExisting <ILifecycleParticipant <ISiloLifecycle>, InsideRuntimeClient>();
            services.TryAddSingleton <IGrainServiceFactory, GrainServiceFactory>();

            services.TryAddSingleton <IFatalErrorHandler, FatalErrorHandler>();

            services.TryAddSingleton <DeploymentLoadPublisher>();

            services.TryAddSingleton <IAsyncTimerFactory, AsyncTimerFactory>();
            services.TryAddSingleton <MembershipTableManager>();
            services.AddFromExisting <IHealthCheckParticipant, MembershipTableManager>();
            services.AddFromExisting <ILifecycleParticipant <ISiloLifecycle>, MembershipTableManager>();
            services.TryAddSingleton <MembershipSystemTarget>();
            services.AddFromExisting <IMembershipService, MembershipSystemTarget>();
            services.TryAddSingleton <IMembershipGossiper, MembershipGossiper>();
            services.TryAddSingleton <IRemoteSiloProber, RemoteSiloProber>();
            services.TryAddSingleton <SiloStatusOracle>();
            services.TryAddFromExisting <ISiloStatusOracle, SiloStatusOracle>();
            services.AddSingleton <ClusterHealthMonitor>();
            services.AddFromExisting <ILifecycleParticipant <ISiloLifecycle>, ClusterHealthMonitor>();
            services.AddFromExisting <IHealthCheckParticipant, ClusterHealthMonitor>();
            services.AddSingleton <MembershipAgent>();
            services.AddFromExisting <ILifecycleParticipant <ISiloLifecycle>, MembershipAgent>();
            services.AddFromExisting <IHealthCheckParticipant, MembershipAgent>();
            services.AddSingleton <MembershipTableCleanupAgent>();
            services.AddFromExisting <ILifecycleParticipant <ISiloLifecycle>, MembershipTableCleanupAgent>();
            services.AddFromExisting <IHealthCheckParticipant, MembershipTableCleanupAgent>();
            services.AddSingleton <SiloStatusListenerManager>();
            services.AddFromExisting <ILifecycleParticipant <ISiloLifecycle>, SiloStatusListenerManager>();
            services.AddSingleton <ClusterMembershipService>();
            services.TryAddFromExisting <IClusterMembershipService, ClusterMembershipService>();
            services.AddFromExisting <ILifecycleParticipant <ISiloLifecycle>, ClusterMembershipService>();

            services.TryAddSingleton <ClientObserverRegistrar>();
            services.TryAddFromExisting <ILifecycleParticipant <ISiloLifecycle>, ClientObserverRegistrar>();
            services.TryAddSingleton <SiloProviderRuntime>();
            services.TryAddFromExisting <IStreamProviderRuntime, SiloProviderRuntime>();
            services.TryAddFromExisting <IProviderRuntime, SiloProviderRuntime>();
            services.TryAddSingleton <ImplicitStreamSubscriberTable>();
            services.TryAddSingleton <MessageFactory>();

            services.TryAddSingleton <Factory <Grain, ILogConsistencyProtocolServices> >(FactoryUtility.Create <Grain, ProtocolServices>);
            services.TryAddSingleton(FactoryUtility.Create <GrainDirectoryPartition>);

            // Placement
            services.AddSingleton <IConfigurationValidator, ActivationCountBasedPlacementOptionsValidator>();
            services.AddSingleton <PlacementService>();
            services.AddSingleton <PlacementStrategyResolver>();
            services.AddSingleton <PlacementDirectorResolver>();
            services.AddSingleton <IPlacementStrategyResolver, ClientObserverPlacementStrategyResolver>();

            // Configure the default placement strategy.
            services.TryAddSingleton <PlacementStrategy, RandomPlacement>();

            // Placement directors
            services.AddPlacementDirector <RandomPlacement, RandomPlacementDirector>();
            services.AddPlacementDirector <PreferLocalPlacement, PreferLocalPlacementDirector>();
            services.AddPlacementDirector <StatelessWorkerPlacement, StatelessWorkerDirector>();
            services.Replace(new ServiceDescriptor(typeof(StatelessWorkerPlacement), sp => new StatelessWorkerPlacement(), ServiceLifetime.Singleton));
            services.AddPlacementDirector <ActivationCountBasedPlacement, ActivationCountPlacementDirector>();
            services.AddPlacementDirector <HashBasedPlacement, HashBasedPlacementDirector>();
            services.AddPlacementDirector <ClientObserversPlacement, ClientObserversPlacementDirector>();

            // Activation selectors
            services.AddSingletonKeyedService <Type, IActivationSelector, RandomPlacementDirector>(typeof(RandomPlacement));
            services.AddSingletonKeyedService <Type, IActivationSelector, StatelessWorkerDirector>(typeof(StatelessWorkerPlacement));

            // Versioning
            services.TryAddSingleton <VersionSelectorManager>();
            services.TryAddSingleton <CachedVersionSelectorManager>();
            // Version selector strategy
            if (!services.Any(x => x.ServiceType == typeof(IVersionStore)))
            {
                services.TryAddSingleton <GrainVersionStore>();
                services.AddFromExisting <IVersionStore, GrainVersionStore>();
            }
            services.AddFromExisting <ILifecycleParticipant <ISiloLifecycle>, GrainVersionStore>();
            services.AddSingletonNamedService <VersionSelectorStrategy, AllCompatibleVersions>(nameof(AllCompatibleVersions));
            services.AddSingletonNamedService <VersionSelectorStrategy, LatestVersion>(nameof(LatestVersion));
            services.AddSingletonNamedService <VersionSelectorStrategy, MinimumVersion>(nameof(MinimumVersion));
            // Versions selectors
            services.AddSingletonKeyedService <Type, IVersionSelector, MinimumVersionSelector>(typeof(MinimumVersion));
            services.AddSingletonKeyedService <Type, IVersionSelector, LatestVersionSelector>(typeof(LatestVersion));
            services.AddSingletonKeyedService <Type, IVersionSelector, AllCompatibleVersionsSelector>(typeof(AllCompatibleVersions));

            // Compatibility
            services.TryAddSingleton <CompatibilityDirectorManager>();
            // Compatability strategy
            services.AddSingletonNamedService <CompatibilityStrategy, AllVersionsCompatible>(nameof(AllVersionsCompatible));
            services.AddSingletonNamedService <CompatibilityStrategy, BackwardCompatible>(nameof(BackwardCompatible));
            services.AddSingletonNamedService <CompatibilityStrategy, StrictVersionCompatible>(nameof(StrictVersionCompatible));
            // Compatability directors
            services.AddSingletonKeyedService <Type, ICompatibilityDirector, BackwardCompatilityDirector>(typeof(BackwardCompatible));
            services.AddSingletonKeyedService <Type, ICompatibilityDirector, AllVersionsCompatibilityDirector>(typeof(AllVersionsCompatible));
            services.AddSingletonKeyedService <Type, ICompatibilityDirector, StrictVersionCompatibilityDirector>(typeof(StrictVersionCompatible));

            services.TryAddSingleton <Factory <IGrainRuntime> >(sp => () => sp.GetRequiredService <IGrainRuntime>());

            // Grain activation
            services.TryAddSingleton <Catalog>();
            services.AddFromExisting <IHealthCheckParticipant, Catalog>();
            services.TryAddSingleton <GrainCreator>();
            services.TryAddSingleton <IGrainActivator, DefaultGrainActivator>();
            services.TryAddScoped <ActivationData.GrainActivationContextFactory>();
            services.TryAddScoped <IGrainActivationContext>(sp => sp.GetRequiredService <ActivationData.GrainActivationContextFactory>().Context);

            services.TryAddSingleton <IStreamSubscriptionManagerAdmin>(sp => new StreamSubscriptionManagerAdmin(sp.GetRequiredService <IStreamProviderRuntime>()));
            services.TryAddSingleton <IConsistentRingProvider>(
                sp =>
            {
                // TODO: make this not sux - jbragg
                var consistentRingOptions = sp.GetRequiredService <IOptions <ConsistentRingOptions> >().Value;
                var siloDetails           = sp.GetRequiredService <ILocalSiloDetails>();
                var loggerFactory         = sp.GetRequiredService <ILoggerFactory>();
                if (consistentRingOptions.UseVirtualBucketsConsistentRing)
                {
                    return(new VirtualBucketsRingProvider(siloDetails.SiloAddress, loggerFactory, consistentRingOptions.NumVirtualBucketsConsistentRing));
                }

                return(new ConsistentRingProvider(siloDetails.SiloAddress, loggerFactory));
            });

            services.TryAddSingleton(typeof(IKeyedServiceCollection <,>), typeof(KeyedServiceCollection <,>));

            // Serialization
            services.TryAddSingleton <SerializationManager>(sp => ActivatorUtilities.CreateInstance <SerializationManager>(sp,
                                                                                                                           sp.GetRequiredService <IOptions <SiloMessagingOptions> >().Value.LargeMessageWarningThreshold));
            services.TryAddSingleton <ITypeResolver, CachedTypeResolver>();
            services.TryAddSingleton <IFieldUtils, FieldUtils>();
            services.AddSingleton <BinaryFormatterSerializer>();
            services.AddSingleton <BinaryFormatterISerializableSerializer>();
            services.AddFromExisting <IKeyedSerializer, BinaryFormatterISerializableSerializer>();
#pragma warning disable CS0618 // Type or member is obsolete
            services.AddSingleton <ILBasedSerializer>();
            services.AddFromExisting <IKeyedSerializer, ILBasedSerializer>();
#pragma warning restore CS0618 // Type or member is obsolete

            // Transactions
            services.TryAddSingleton <ITransactionAgent, DisabledTransactionAgent>();

            // Application Parts
            services.TryAddSingleton <IApplicationPartManager>(applicationPartManager);
            applicationPartManager.AddApplicationPart(new AssemblyPart(typeof(RuntimeVersion).Assembly)
            {
                IsFrameworkAssembly = true
            });
            applicationPartManager.AddApplicationPart(new AssemblyPart(typeof(Silo).Assembly)
            {
                IsFrameworkAssembly = true
            });
            applicationPartManager.AddFeatureProvider(new BuiltInTypesSerializationFeaturePopulator());
            applicationPartManager.AddFeatureProvider(new AssemblyAttributeFeatureProvider <GrainInterfaceFeature>());
            applicationPartManager.AddFeatureProvider(new AssemblyAttributeFeatureProvider <GrainClassFeature>());
            applicationPartManager.AddFeatureProvider(new AssemblyAttributeFeatureProvider <SerializerFeature>());
            services.AddTransient <IConfigurationValidator, ApplicationPartValidator>();

            // Type metadata
            services.AddSingleton <SiloManifestProvider>();
            services.AddSingleton <SiloManifest>(sp => sp.GetRequiredService <SiloManifestProvider>().SiloManifest);
            services.AddSingleton <Metadata.GrainTypeResolver>();
            services.AddSingleton <Metadata.IGrainTypeProvider, LegacyGrainTypeResolver>();
            services.AddSingleton <GrainPropertiesResolver>();
            services.AddSingleton <GrainInterfaceIdResolver>();
            services.AddSingleton <Metadata.IGrainTypeProvider, AttributeGrainTypeProvider>();
            services.AddSingleton <IGrainInterfacePropertiesProvider, AttributeGrainInterfacePropertiesProvider>();
            services.AddSingleton <IGrainPropertiesProvider, AttributeGrainPropertiesProvider>();
            services.AddSingleton <IGrainInterfacePropertiesProvider, DiagnosticInfoGrainPropertiesProvider>();
            services.AddSingleton <IGrainPropertiesProvider, DiagnosticInfoGrainPropertiesProvider>();
            services.AddSingleton <IGrainPropertiesProvider, ImplementedInterfaceProvider>();
            services.AddSingleton <ClusterManifestProvider>();
            services.AddFromExisting <IClusterManifestProvider, ClusterManifestProvider>();
            services.AddFromExisting <ILifecycleParticipant <ISiloLifecycle>, ClusterManifestProvider>();

            //Add default option formatter if none is configured, for options which are required to be configured
            services.ConfigureFormatter <SiloOptions>();
            services.ConfigureFormatter <SchedulingOptions>();
            services.ConfigureFormatter <PerformanceTuningOptions>();
            services.ConfigureFormatter <SerializationProviderOptions>();
            services.ConfigureFormatter <ConnectionOptions>();
            services.ConfigureFormatter <SiloMessagingOptions>();
            services.ConfigureFormatter <TypeManagementOptions>();
            services.ConfigureFormatter <ClusterMembershipOptions>();
            services.ConfigureFormatter <GrainDirectoryOptions>();
            services.ConfigureFormatter <ActivationCountBasedPlacementOptions>();
            services.ConfigureFormatter <GrainCollectionOptions>();
            services.ConfigureFormatter <GrainVersioningOptions>();
            services.ConfigureFormatter <ConsistentRingOptions>();
            services.ConfigureFormatter <StatisticsOptions>();
            services.ConfigureFormatter <TelemetryOptions>();
            services.ConfigureFormatter <LoadSheddingOptions>();
            services.ConfigureFormatter <EndpointOptions>();
            services.ConfigureFormatter <ClusterOptions>();

            // This validator needs to construct the IMembershipOracle and the IMembershipTable
            // so move it in the end so other validator are called first
            services.AddTransient <IConfigurationValidator, ClusterOptionsValidator>();
            services.AddTransient <IConfigurationValidator, SiloClusteringValidator>();
            services.AddTransient <IConfigurationValidator, DevelopmentClusterMembershipOptionsValidator>();

            // Enable hosted client.
            services.TryAddSingleton <HostedClient>();
            services.AddFromExisting <ILifecycleParticipant <ISiloLifecycle>, HostedClient>();
            services.TryAddSingleton <InvokableObjectManager>();
            services.TryAddSingleton <InternalClusterClient>();
            services.TryAddFromExisting <IInternalClusterClient, InternalClusterClient>();
            services.TryAddFromExisting <IClusterClient, InternalClusterClient>();

            // Enable collection specific Age limits
            services.AddOptions <GrainCollectionOptions>()
            .Configure <IApplicationPartManager>((options, parts) =>
            {
                var grainClasses = new GrainClassFeature();
                parts.PopulateFeature(grainClasses);

                foreach (var grainClass in grainClasses.Classes)
                {
                    var attr = grainClass.ClassType.GetCustomAttribute <CollectionAgeLimitAttribute>();
                    if (attr != null)
                    {
                        var className = TypeUtils.GetFullName(grainClass.ClassType);
                        options.ClassSpecificCollectionAge[className] = attr.Amount;
                    }
                }
            });

            // Validate all CollectionAgeLimit values for the right configuration.
            services.AddTransient <IConfigurationValidator, GrainCollectionOptionsValidator>();

            services.AddTransient <IConfigurationValidator, LoadSheddingValidator>();

            services.TryAddSingleton <ITimerManager, TimerManagerImpl>();

            // persistent state facet support
            services.TryAddSingleton <IPersistentStateFactory, PersistentStateFactory>();
            services.TryAddSingleton(typeof(IAttributeToFactoryMapper <PersistentStateAttribute>), typeof(PersistentStateAttributeMapper));

            // Networking
            services.TryAddSingleton <ConnectionCommon>();
            services.TryAddSingleton <ConnectionManager>();
            services.AddSingleton <ILifecycleParticipant <ISiloLifecycle>, ConnectionManagerLifecycleAdapter <ISiloLifecycle> >();
            services.AddSingleton <ILifecycleParticipant <ISiloLifecycle>, SiloConnectionMaintainer>();

            services.AddSingletonKeyedService <object, IConnectionFactory>(
                SiloConnectionFactory.ServicesKey,
                (sp, key) => ActivatorUtilities.CreateInstance <SocketConnectionFactory>(sp));
            services.AddSingletonKeyedService <object, IConnectionListenerFactory>(
                SiloConnectionListener.ServicesKey,
                (sp, key) => ActivatorUtilities.CreateInstance <SocketConnectionListenerFactory>(sp));
            services.AddSingletonKeyedService <object, IConnectionListenerFactory>(
                GatewayConnectionListener.ServicesKey,
                (sp, key) => ActivatorUtilities.CreateInstance <SocketConnectionListenerFactory>(sp));

            services.TryAddTransient <IMessageSerializer>(sp => ActivatorUtilities.CreateInstance <MessageSerializer>(sp,
                                                                                                                      sp.GetRequiredService <IOptions <SiloMessagingOptions> >().Value.MaxMessageHeaderSize,
                                                                                                                      sp.GetRequiredService <IOptions <SiloMessagingOptions> >().Value.MaxMessageBodySize));
            services.TryAddSingleton <ConnectionFactory, SiloConnectionFactory>();
            services.AddSingleton <NetworkingTrace>();
            services.AddSingleton <RuntimeMessagingTrace>();
            services.AddFromExisting <MessagingTrace, RuntimeMessagingTrace>();

            // Use Orleans server.
            services.AddSingleton <ILifecycleParticipant <ISiloLifecycle>, SiloConnectionListener>();
            services.AddSingleton <ILifecycleParticipant <ISiloLifecycle>, GatewayConnectionListener>();
            services.AddSingleton <SocketSchedulers>();
            services.AddSingleton <SharedMemoryPool>();
        }
 /// <summary>
 /// Utility method for add external assembly to SiloBuilder
 /// </summary>
 /// <param name="applicationPartManager"></param>
 /// <param name="assembly"></param>
 public static void AddDynamicPart(this IApplicationPartManager applicationPartManager, Assembly assembly)
 {
     applicationPartManager.AddApplicationPart(assembly).WithReferences();
 }
示例#17
0
 public static void AddKanekoParts(this IApplicationPartManager manager)
 {
     manager.AddApplicationPart(typeof(UtcUIDGrain).Assembly).WithReferences();
 }
示例#18
0
文件: Program.cs 项目: trevex/CueX
 private static void AddHostApplicationParts(IApplicationPartManager parts)
 {
     GridConfigurationHelper.AddSiloApplicationParts(parts);
     parts.AddApplicationPart(typeof(SimpleGrain).Assembly).WithReferences();
 }
示例#19
0
 /// <summary>
 /// Adds the application.
 /// </summary>
 /// <param name="manager">The manager.</param>
 /// <returns>The application part manager.</returns>
 public static IApplicationPartManager AddApp(this IApplicationPartManager manager)
 {
     manager.AddApplicationPart(new AssemblyPart(typeof(Setup).Assembly));
     return(manager);
 }
示例#20
0
 public static void AddMyParts(this IApplicationPartManager builder)
 {
     builder.AddApplicationPart(SquidexEntities.Assembly);
     builder.AddApplicationPart(SquidexInfrastructure.Assembly);
 }
 public static IApplicationPartManager AddMongoGrains(this IApplicationPartManager manager) =>
 manager.AddApplicationPart(typeof(MongoManageStatisticsGrain <>).Assembly)
 .AddApplicationPart(typeof(MongoGetStatisticsGrain <>).Assembly);
示例#22
0
 static void UseOrleankka(IApplicationPartManager apm, IServiceCollection services)
 {
     Configure(apm, services);
     apm.AddApplicationPart(typeof(IClientEndpoint).Assembly)
     .WithCodeGeneration();
 }
示例#23
0
 public static void AddSiloApplicationParts(IApplicationPartManager parts)
 {
     parts.AddApplicationPart(typeof(GridPartitionGrain).Assembly).WithReferences();
     parts.AddApplicationPart(typeof(GridConfigurationGrain).Assembly).WithReferences();
 }
示例#24
0
 public static IApplicationPartManager AddTarantoolGrains(this IApplicationPartManager manager) =>
 manager.AddApplicationPart(typeof(TarantoolManageStatisticsGrain <>).Assembly)
 .AddApplicationPart(typeof(TarantoolGetStatisticsGrain <>).Assembly);