Beispiel #1
0
        public static IServiceCollection AddSeaOrDewHandlers(this IServiceCollection services, Action <SeaOrDewOptions> optionsSetup)
        {
            var options = new SeaOrDewOptions();

            optionsSetup?.Invoke(options);
            return(services.AddSeaOrDewHandlers(options));
        }
Beispiel #2
0
 public static void LoadQueryHandlersFromAssemblyUnderNamespace(
     this SeaOrDewOptions options,
     Assembly assembly,
     string namespacePrefix)
 {
     options.LoadQueryHandlers(new HandlerSource(assembly, namespacePrefix));
 }
Beispiel #3
0
 public static void LoadAllHandlersFromAssembly(
     this SeaOrDewOptions options,
     Assembly assembly)
 {
     options.LoadCommandHandlersFromAssembly(assembly);
     options.LoadQueryHandlersFromAssembly(assembly);
 }
Beispiel #4
0
 public static void LoadAssemblyHandlersUnderNamespace(
     this SeaOrDewOptions options,
     Assembly assembly,
     string namespacePrefix)
 {
     options.LoadCommandHandlersFromAssemblyUnderNamespace(assembly, namespacePrefix);
     options.LoadQueryHandlersFromAssemblyUnderNamespace(assembly, namespacePrefix);
 }
Beispiel #5
0
        public static IServiceCollection AddSeaOrDewHandlers(this IServiceCollection services, SeaOrDewOptions options = null)
        {
            var descriptors = new[] {
                new ServiceDescriptor(typeof(QueryHandler), typeof(QueryHandler), options?.ServiceLifetime ?? ServiceLifetime.Scoped),
                new ServiceDescriptor(typeof(CommandHandler), typeof(CommandHandler), options?.ServiceLifetime ?? ServiceLifetime.Scoped)
            };

            if (options?.TryAdd == true)
            {
                services.TryAdd(descriptors);
            }
            else
            {
                services.Add(descriptors);
            }
            if (options != null)
            {
                foreach (var handlerSource in options.CommandHandlerAssemblies)
                {
                    AddInstancesOfGenericTypeDefinition(services, handlerSource.Assembly, handlerSource.NamespacePrefix, typeof(ICustomCommandHandler <,>), options.ServiceLifetime, options.TryAdd);
                }
                foreach (var handlerSource in options.QueryHandlerAssemblies)
                {
                    AddInstancesOfGenericTypeDefinition(services, handlerSource.Assembly, handlerSource.NamespacePrefix, typeof(IQueryHandler <,>), options.ServiceLifetime, options.TryAdd);
                }
            }
            return(services);
        }
Beispiel #6
0
 public static void LoadQueryHandlersFromAssembly(
     this SeaOrDewOptions options,
     Assembly assembly)
 {
     options.LoadQueryHandlers(new HandlerSource(assembly));
 }