public SwashbuckleOrleansDescriptionProvider(IServiceProvider services) { var appPartsMgr = services.GetRequiredService <IApplicationPartManager>(); this.grainInterfaceFeature = appPartsMgr.CreateAndPopulateFeature <Orleans.Metadata.GrainInterfaceFeature>(); this.metadataProvider = services.GetRequiredService <IModelMetadataProvider>(); }
private static Dictionary <int, InvokerData> CreateInvokerMap(GrainInterfaceFeature grainInterfaceFeature) { var result = new Dictionary <int, InvokerData>(); foreach (var grainInterfaceMetadata in grainInterfaceFeature.Interfaces) { int ifaceId = grainInterfaceMetadata.InterfaceId; if (result.ContainsKey(ifaceId)) { throw new InvalidOperationException($"Grain method invoker classes {result[ifaceId]} and {grainInterfaceMetadata.InvokerType.FullName} use the same interface id {ifaceId}"); } result[ifaceId] = new InvokerData(grainInterfaceMetadata.InvokerType); } return(result); }
private static List <Type> DiscoverGrainTypesToMap(GrainInterfaceFeature grainInterfaceFeature) { var grainTypesToMap = new List <Type>(); foreach (var grainInterfaceMetadata in grainInterfaceFeature.Interfaces) { var grainType = grainInterfaceMetadata.InterfaceType; // Only add to the list grains that either have the top-level route attribute or has one of the method attributes if (grainType.GetCustomAttributes(true).Contains(_routeAttributeType) || grainType.GetMethods() .Any(m => m.GetCustomAttributes(true) .Any(attr => attr.GetType() == _routeAttributeType || _methodAttributeTypes.Contains(attr.GetType())))) { grainTypesToMap.Add(grainType); } } return(grainTypesToMap); }
public void RuntimeCodeGen_AddsSupportClasses() { var partManager = new ApplicationPartManager(); partManager.AddApplicationPart(typeof(IRuntimeCodeGenGrain).Assembly); partManager.AddFeatureProvider(new AssemblyAttributeFeatureProvider <GrainInterfaceFeature>()); partManager.AddFeatureProvider(new AssemblyAttributeFeatureProvider <GrainClassFeature>()); partManager.AddFeatureProvider(new AssemblyAttributeFeatureProvider <SerializerFeature>()); var interfaceFeature = new GrainInterfaceFeature(); partManager.PopulateFeature(interfaceFeature); Assert.DoesNotContain(interfaceFeature.Interfaces, i => i.InterfaceType == typeof(IRuntimeCodeGenGrain)); var classFeature = new GrainClassFeature(); partManager.PopulateFeature(classFeature); Assert.DoesNotContain(classFeature.Classes, c => c.ClassType == typeof(RuntimeCodeGenGrain)); var serializerFeature = new SerializerFeature(); partManager.PopulateFeature(serializerFeature); Assert.DoesNotContain(serializerFeature.SerializerTypes, s => s.Target == typeof(RuntimeCodeGenPoco)); partManager.AddApplicationPart(typeof(IRuntimeCodeGenGrain).Assembly).WithCodeGeneration(); interfaceFeature = new GrainInterfaceFeature(); partManager.PopulateFeature(interfaceFeature); Assert.Contains(interfaceFeature.Interfaces, i => i.InterfaceType == typeof(IRuntimeCodeGenGrain)); classFeature = new GrainClassFeature(); partManager.PopulateFeature(classFeature); Assert.Contains(classFeature.Classes, c => c.ClassType == typeof(RuntimeCodeGenGrain)); serializerFeature = new SerializerFeature(); partManager.PopulateFeature(serializerFeature); Assert.Contains(serializerFeature.SerializerTypes, s => s.Target == typeof(RuntimeCodeGenPoco)); }
/// <inheritdoc /> public void ValidateConfiguration() { var hasApplicationAssembly = this.applicationPartManager.ApplicationParts.OfType <AssemblyPart>().Any(part => !part.IsFrameworkAssembly); if (!hasApplicationAssembly) { throw new OrleansConfigurationException( $"No application assemblies were added to {nameof(ApplicationPartManager)}." + $" Add assemblies using the {nameof(ApplicationPartManagerExtensions.AddApplicationPart)}({nameof(Assembly)}) extension method on the client builder."); } // Ensure there is a non-framework assembly which has had code generation executed on it. var hasCodeGenRun = this.applicationPartManager.ApplicationParts .OfType <AssemblyPart>() .Any(part => !part.IsFrameworkAssembly && part.Assembly.GetCustomAttribute <FeaturePopulatorAttribute>() != null); if (!hasCodeGenRun) { throw new OrleansConfigurationException( $"None of the assemblies added to {nameof(ApplicationPartManager)} contain generated code." + " Ensure that code generation has been executed for grain interface and class assemblies."); } var allProviders = this.applicationPartManager.FeatureProviders; var nonFrameworkParts = this.applicationPartManager.ApplicationParts .Where(part => !(part is AssemblyPart asm) || !asm.IsFrameworkAssembly) .ToList(); var isSilo = this.serviceProvider.GetService(typeof(ILocalSiloDetails)) != null; if (isSilo) { var providers = allProviders.OfType <IApplicationFeatureProvider <GrainClassFeature> >(); var grains = new GrainClassFeature(); foreach (var provider in providers) { provider.PopulateFeature(nonFrameworkParts, grains); } var hasGrains = grains.Classes.Any(); if (!hasGrains) { throw new OrleansConfigurationException( $"None of the assemblies added to {nameof(ApplicationPartManager)} contain generated code for grain classes." + " Ensure that code generation has been executed for grain interface and grain class assemblies and that they have been added as application parts."); } } { var providers = allProviders.OfType <IApplicationFeatureProvider <GrainInterfaceFeature> >(); var grainInterfaces = new GrainInterfaceFeature(); foreach (var provider in providers) { provider.PopulateFeature(nonFrameworkParts, grainInterfaces); } bool hasGrainInterfaces = grainInterfaces.Interfaces.Any(); if (!hasGrainInterfaces) { throw new OrleansConfigurationException( $"None of the assemblies added to {nameof(ApplicationPartManager)} contain generated code for grain interfaces." + " Ensure that code generation has been executed for grain interface and grain class assemblies and that they have been added as application parts."); } } }