You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

implicit-registration.cs 549 B

123456789101112
  1. public static ServiceCollection RegisterImplicitServices(this ServiceCollection collection, Type interfaceType, Type activatorType)
  2. {
  3. // Get all types in the executing assembly. There are many ways to do this, but this is fastest.
  4. foreach (var type in typeof(Program).Assembly.GetTypes())
  5. {
  6. if (interfaceType.IsAssignableFrom(type) && !type.IsAbstract)
  7. collection.AddSingleton(interfaceType, type);
  8. }
  9. // Register the activator so you can activate the instances.
  10. collection.AddSingleton(activatorType);
  11. }