private static ImmutableDictionary <GrainType, GrainProperties> CreateGrainManifest( IEnumerable <IGrainPropertiesProvider> grainMetadataProviders, IApplicationPartManager applicationPartManager, GrainTypeResolver grainTypeProvider) { var feature = applicationPartManager.CreateAndPopulateFeature <GrainClassFeature>(); var builder = ImmutableDictionary.CreateBuilder <GrainType, GrainProperties>(); foreach (var value in feature.Classes) { var grainClass = value.ClassType; var grainType = grainTypeProvider.GetGrainType(grainClass); var properties = new Dictionary <string, string>(); foreach (var provider in grainMetadataProviders) { provider.Populate(grainClass, grainType, properties); } var result = new GrainProperties(properties.ToImmutableDictionary()); if (builder.ContainsKey(grainType)) { throw new InvalidOperationException($"An entry with the key {grainType} is already present." + $"\nExisting: {builder[grainType].ToDetailedString()}\nTrying to add: {result.ToDetailedString()}" + "\nConsider using the [GrainType(\"name\")] attribute to give these classes unique names."); } builder.Add(grainType, result); } return(builder.ToImmutable()); }
private static (ImmutableDictionary <GrainType, GrainProperties>, ImmutableDictionary <GrainType, Type>) CreateGrainManifest( IEnumerable <IGrainPropertiesProvider> grainMetadataProviders, IOptions <GrainTypeOptions> grainTypeOptions, GrainTypeResolver grainTypeProvider) { var propertiesMap = ImmutableDictionary.CreateBuilder <GrainType, GrainProperties>(); var typeMap = ImmutableDictionary.CreateBuilder <GrainType, Type>(); foreach (var grainClass in grainTypeOptions.Value.Classes) { var grainType = grainTypeProvider.GetGrainType(grainClass); var properties = new Dictionary <string, string>(); foreach (var provider in grainMetadataProviders) { provider.Populate(grainClass, grainType, properties); } var result = new GrainProperties(properties.ToImmutableDictionary()); if (propertiesMap.ContainsKey(grainType)) { throw new InvalidOperationException($"An entry with the key {grainType} is already present." + $"\nExisting: {propertiesMap[grainType].ToDetailedString()}\nTrying to add: {result.ToDetailedString()}" + "\nConsider using the [GrainType(\"name\")] attribute to give these classes unique names."); } propertiesMap.Add(grainType, result); typeMap.Add(grainType, grainClass); } return(propertiesMap.ToImmutable(), typeMap.ToImmutable()); }