Exemple #1
0
 public static IImplementationTypeSelector RegisterHandlers(this IImplementationTypeSelector selector, Type type)
 {
     return(selector.AddClasses(c => c.AssignableTo(type))
            .UsingRegistrationStrategy(RegistrationStrategy.Append)
            .AsImplementedInterfaces()
            .WithScopedLifetime());
 }
Exemple #2
0
 private static void AddTypes(this IImplementationTypeSelector selector)
 {
     selector
     .AddClasses(classes => classes.AssignableTo(typeof(IEventHandler <>)))
     .AsImplementedInterfaces()
     .WithTransientLifetime();
 }
 public static IImplementationTypeSelector AddAttributes(this IImplementationTypeSelector implementationTypeSelector)
 {
     return
         (implementationTypeSelector
          .AddClasses()
          .UsingAttributes());
 }
 public static IImplementationTypeSelector AddSingletonInterfaces(this IImplementationTypeSelector implementationTypeSelector)
 {
     return
         (implementationTypeSelector
          .AddClasses(classes => classes.AssignableTo <ISingletonService>())
          .AsImplementedInterfaces()
          .WithSingletonLifetime());
 }
 public static IImplementationTypeSelector AddTransientInterfaces(this IImplementationTypeSelector implementationTypeSelector)
 {
     return
         (implementationTypeSelector
          .AddClasses(classes => classes.AssignableTo <ITransientService>())
          .AsImplementedInterfaces()
          .WithTransientLifetime());
 }
Exemple #6
0
        private static void AddLuigiTypes(this IImplementationTypeSelector selector)
        {
            selector
            .AddClasses(classes => classes.AssignableTo(typeof(IQueryPipeline <,>)))
            .AsImplementedInterfaces()
            .WithTransientLifetime()
            .AddClasses(classes => classes.AssignableTo(typeof(IQueryPipe <,>)))
            .AsSelf()
            .WithTransientLifetime()

            .AddClasses(classes => classes.AssignableTo(typeof(IQueryPipeline <, ,>)))
            .AsImplementedInterfaces()
            .WithTransientLifetime()
            .AddClasses(classes => classes.AssignableTo(typeof(IQueryPipe <, ,>)))
            .AsSelf()
            .WithTransientLifetime()

            .AddClasses(classes => classes.AssignableTo(typeof(IQueryHandler <,>)))
            .AsImplementedInterfaces()
            .WithTransientLifetime()

            .AddClasses(classes => classes.AssignableTo(typeof(ICommandPipeline <,>)))
            .AsImplementedInterfaces()
            .WithTransientLifetime()
            .AddClasses(classes => classes.AssignableTo(typeof(ICommandPipe <,>)))
            .AsSelf()
            .WithTransientLifetime()

            .AddClasses(classes => classes.AssignableTo(typeof(ICommandPipeline <>)))
            .AsImplementedInterfaces()
            .WithTransientLifetime()
            .AddClasses(classes => classes.AssignableTo(typeof(ICommandPipe <>)))
            .AsSelf()
            .WithTransientLifetime()

            .AddClasses(classes => classes.AssignableTo(typeof(ICommandHandler <>)))
            .AsImplementedInterfaces()
            .WithTransientLifetime()

            .AddClasses(classes => classes.AssignableTo(typeof(IEventPipeline <,>)))
            .AsImplementedInterfaces()
            .WithTransientLifetime()
            .AddClasses(classes => classes.AssignableTo(typeof(IEventPipe <,>)))
            .AsSelf()
            .WithTransientLifetime()

            .AddClasses(classes => classes.AssignableTo(typeof(IEventPipeline <>)))
            .AsImplementedInterfaces()
            .WithTransientLifetime()
            .AddClasses(classes => classes.AssignableTo(typeof(IEventPipe <>)))
            .AsSelf()
            .WithTransientLifetime()

            .AddClasses(classes => classes.AssignableTo(typeof(IEventHandler <>)))
            .AsImplementedInterfaces()
            .WithTransientLifetime();
        }
 internal static IImplementationTypeSelector RegisterForLifetime(
     this IImplementationTypeSelector typeSelector,
     ServiceLifetime lifetime)
 {
     return(typeSelector
            .AddClasses(classes => classes.Filter(lifetime))
            .AsSelf()
            .AsImplementedInterfaces()
            .WithLifetime(lifetime));
 }
        private static IImplementationTypeSelector AddClassesFromInterfaces(this IImplementationTypeSelector selector)
        {
            //singleton
            selector.AddClasses(classes => classes.AssignableTo <ISingletonLifetime>(), true)
            .UsingRegistrationStrategy(RegistrationStrategy.Skip)
            .AsMatchingInterface()
            .WithSingletonLifetime()

            .AddClasses(classes => classes.AssignableTo <ISelfSingletonLifetime>(), true)
            .UsingRegistrationStrategy(RegistrationStrategy.Skip)
            .AsSelf()
            .WithSingletonLifetime()

            //transient
            .AddClasses(classes => classes.AssignableTo <ITransientLifetime>(), true)
            .UsingRegistrationStrategy(RegistrationStrategy.Skip)
            .AsMatchingInterface()
            .WithTransientLifetime()

            .AddClasses(classes => classes.AssignableTo <ISelfTransientLifetime>(), true)
            .UsingRegistrationStrategy(RegistrationStrategy.Skip)
            .AsSelf()
            .WithTransientLifetime()

            //scoped
            .AddClasses(classes => classes.AssignableTo <IScopedLifetime>(), true)
            .UsingRegistrationStrategy(RegistrationStrategy.Skip)
            .AsMatchingInterface()
            .WithScopedLifetime()

            .AddClasses(classes => classes.AssignableTo <ISelfScopedLifetime>(), true)
            .UsingRegistrationStrategy(RegistrationStrategy.Skip)
            .AsSelf()
            .WithScopedLifetime();

            return(selector);
        }
Exemple #9
0
 /// <summary>
 /// Scans and registers all <see cref="IValidator{T}"/>.
 /// </summary>
 /// <param name="selector">The selector used to scan for classes.</param>
 /// <returns>The selector.</returns>
 public static IImplementationTypeSelector AddValidators(this IImplementationTypeSelector selector)
 {
     return(selector.AddClasses(classes => classes.AssignableTo(typeof(IValidator <>)))
            .AsImplementedInterfaces()
            .WithScopedLifetime());
 }
Exemple #10
0
 /// <summary>
 /// Registers all <see cref="ValidationBehavior{TRequest, TResponse}"/>
 /// that uses <see cref="IValidator{TRequest}"/>
 /// as MediatR <see cref="IPipelineBehavior{TRequest, TResponse}"/>.
 ///
 /// Automatic command and query validation should work as long there is a <see cref="IValidator{TRequest}"/> for the handler.
 /// </summary>
 /// <param name="selector">The selector used to scan for classes.</param>
 /// <returns>The selector.</returns>
 public static IImplementationTypeSelector AddValidationBehaviors(this IImplementationTypeSelector selector)
 {
     return(selector.AddClasses(classes => classes.AssignableTo(typeof(ValidationBehavior <,>)))
            .As(typeof(IPipelineBehavior <,>))
            .WithTransientLifetime());
 }
Exemple #11
0
 public static IImplementationTypeSelector InjectableAttribute(this IImplementationTypeSelector selector, ServiceLifetime lifeTime)
 {
     return(selector.AddClasses(c => c.WithAttribute <InjectableAttribute>(i => i.Lifetime == lifeTime))
            .AsImplementedInterfaces()
            .WithLifetime(lifeTime));
 }