fork download
  1. /// <summary>
  2. /// Registers grains from specified assembly which are sub classes of <see cref="Grain"/>.
  3. /// Grains that implement <see cref="IContextProvider{TContext}"/> are registered with a proxy implementation
  4. /// that is scoped to the grain's lifetime and retrieves the context from the grain itself avoiding circular dependencies.
  5. /// </summary>
  6. /// <param name="container">The container to add registrations to</param>
  7. /// <param name="grainsAssembly">Assembly to scan for grain types</param>
  8. public static void RegisterGrains(Container container, Assembly grainsAssembly)
  9. {
  10. Guard.CheckNullArgument(container, nameof(container));
  11.  
  12. var grainConcreteTypes =
  13. (from exportedType in grainsAssembly.GetExportedTypes()
  14. where exportedType.IsSubclassOf(typeof(Grain)) && !exportedType.IsAbstract
  15. select exportedType)
  16. .ToArray();
  17.  
  18. foreach (var grainType in grainConcreteTypes)
  19. {
  20. container.Register(grainType, grainType, Lifestyle.Transient);
  21. }
  22.  
  23. var contextTypesProvidedByGrains =
  24. (from grainType in grainConcreteTypes
  25. from serviceType in grainType.GetInterfaces()
  26. where serviceType.IsGenericOf(typeof(IContextProvider<>))
  27. let contextProviderServiceType = serviceType
  28. let providedContextType = contextProviderServiceType.GetGenericArguments()[0]
  29. from inheritedContextType in providedContextType.GetInheritedTypes()
  30. select inheritedContextType)
  31. .Distinct();
  32.  
  33. // We explicitly register context providers without single open-generic batch registrations for two reasons:
  34. // 1. It's more efficient to resolve services that were registered standard way, without open-generic batch registrations
  35. // 2. It allows to register context providers that aren't grains without conflicts
  36. foreach (var contextType in contextTypesProvidedByGrains)
  37. {
  38. container.Register(typeof(IContextProvider<>).MakeGenericType(contextType), typeof(GrainContextProviderProxy<>).MakeGenericType(contextType), Lifestyle.Singleton);
  39. }
  40. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(8,14): error CS1525: Unexpected symbol `void', expecting `class', `delegate', `enum', `interface', `partial', or `struct'
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty