BasicConventionalRegistrar.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Reflection;
  2. using Castle.DynamicProxy;
  3. using Castle.MicroKernel.Registration;
  4. namespace Abp.Dependency
  5. {
  6. /// <summary>
  7. /// This class is used to register basic dependency implementations such as <see cref="ITransientDependency"/> and <see cref="ISingletonDependency"/>.
  8. /// </summary>
  9. public class BasicConventionalRegistrar : IConventionalDependencyRegistrar
  10. {
  11. public void RegisterAssembly(IConventionalRegistrationContext context)
  12. {
  13. //Transient
  14. context.IocManager.IocContainer.Register(
  15. Classes.FromAssembly(context.Assembly)
  16. .IncludeNonPublicTypes()
  17. .BasedOn<ITransientDependency>()
  18. .If(type => !type.GetTypeInfo().IsGenericTypeDefinition)
  19. .WithService.Self()
  20. .WithService.DefaultInterfaces()
  21. .LifestyleTransient()
  22. );
  23. //Singleton
  24. context.IocManager.IocContainer.Register(
  25. Classes.FromAssembly(context.Assembly)
  26. .IncludeNonPublicTypes()
  27. .BasedOn<ISingletonDependency>()
  28. .If(type => !type.GetTypeInfo().IsGenericTypeDefinition)
  29. .WithService.Self()
  30. .WithService.DefaultInterfaces()
  31. .LifestyleSingleton()
  32. );
  33. //Windsor Interceptors
  34. context.IocManager.IocContainer.Register(
  35. Classes.FromAssembly(context.Assembly)
  36. .IncludeNonPublicTypes()
  37. .BasedOn<IInterceptor>()
  38. .If(type => !type.GetTypeInfo().IsGenericTypeDefinition)
  39. .WithService.Self()
  40. .LifestyleTransient()
  41. );
  42. }
  43. }
  44. }