예제 #1
0
        public override void Run(ServiceProviderContainer container, Assembly[] assemblies, CrudlessOptions options)
        {
            bool IfNotHandled(ConditionalContext c) => !c.Handled;

            container.Register(typeof(IRequestHandler <>), assemblies);
            container.Register(typeof(IRequestHandler <,>), assemblies);

            container.Register(typeof(CreateRequestHandler <,>), assemblies);
            container.Register(typeof(CreateRequestHandler <, ,>), assemblies);
            container.RegisterConditional(typeof(IRequestHandler <>), typeof(CreateRequestHandler <,>), IfNotHandled);
            container.RegisterConditional(typeof(IRequestHandler <,>), typeof(CreateRequestHandler <, ,>), IfNotHandled);

            container.Register(typeof(CreateAllRequestHandler <,>), assemblies);
            container.Register(typeof(CreateAllRequestHandler <, ,>), assemblies);
            container.RegisterConditional(typeof(IRequestHandler <>), typeof(CreateAllRequestHandler <,>), IfNotHandled);
            container.RegisterConditional(typeof(IRequestHandler <,>), typeof(CreateAllRequestHandler <, ,>), IfNotHandled);

            container.Register(typeof(GetRequestHandler <, ,>), assemblies);
            container.RegisterConditional(typeof(IRequestHandler <,>), typeof(GetRequestHandler <, ,>), IfNotHandled);

            container.Register(typeof(GetAllRequestHandler <, ,>), assemblies);
            container.RegisterConditional(typeof(IRequestHandler <,>), typeof(GetAllRequestHandler <, ,>), IfNotHandled);

            container.Register(typeof(PagedGetAllRequestHandler <, ,>), assemblies);
            container.RegisterConditional(typeof(IRequestHandler <,>), typeof(PagedGetAllRequestHandler <, ,>), IfNotHandled);

            container.Register(typeof(UpdateRequestHandler <,>), assemblies);
            container.Register(typeof(UpdateRequestHandler <, ,>), assemblies);
            container.RegisterConditional(typeof(IRequestHandler <>), typeof(UpdateRequestHandler <,>), IfNotHandled);
            container.RegisterConditional(typeof(IRequestHandler <,>), typeof(UpdateRequestHandler <, ,>), IfNotHandled);

            container.Register(typeof(UpdateAllRequestHandler <,>), assemblies);
            container.Register(typeof(UpdateAllRequestHandler <, ,>), assemblies);
            container.RegisterConditional(typeof(IRequestHandler <>), typeof(UpdateAllRequestHandler <,>), IfNotHandled);
            container.RegisterConditional(typeof(IRequestHandler <,>), typeof(UpdateAllRequestHandler <, ,>), IfNotHandled);

            container.Register(typeof(DeleteRequestHandler <,>), assemblies);
            container.Register(typeof(DeleteRequestHandler <, ,>), assemblies);
            container.RegisterConditional(typeof(IRequestHandler <>), typeof(DeleteRequestHandler <,>), IfNotHandled);
            container.RegisterConditional(typeof(IRequestHandler <,>), typeof(DeleteRequestHandler <, ,>), IfNotHandled);

            container.Register(typeof(DeleteAllRequestHandler <,>), assemblies);
            container.Register(typeof(DeleteAllRequestHandler <, ,>), assemblies);
            container.RegisterConditional(typeof(IRequestHandler <>), typeof(DeleteAllRequestHandler <,>), IfNotHandled);
            container.RegisterConditional(typeof(IRequestHandler <,>), typeof(DeleteAllRequestHandler <, ,>), IfNotHandled);

            container.Register(typeof(SaveRequestHandler <,>), assemblies);
            container.Register(typeof(SaveRequestHandler <, ,>), assemblies);
            container.RegisterConditional(typeof(IRequestHandler <>), typeof(SaveRequestHandler <,>), IfNotHandled);
            container.RegisterConditional(typeof(IRequestHandler <,>), typeof(SaveRequestHandler <, ,>), IfNotHandled);

            container.Register(typeof(MergeRequestHandler <,>), assemblies);
            container.Register(typeof(MergeRequestHandler <, ,>), assemblies);
            container.RegisterConditional(typeof(IRequestHandler <>), typeof(MergeRequestHandler <,>), IfNotHandled);
            container.RegisterConditional(typeof(IRequestHandler <,>), typeof(MergeRequestHandler <, ,>), IfNotHandled);

            container.Register(typeof(SynchronizeRequestHandler <,>), assemblies);
            container.Register(typeof(SynchronizeRequestHandler <, ,>), assemblies);
            container.RegisterConditional(typeof(IRequestHandler <>), typeof(SynchronizeRequestHandler <,>), IfNotHandled);
            container.RegisterConditional(typeof(IRequestHandler <,>), typeof(SynchronizeRequestHandler <, ,>), IfNotHandled);
        }
예제 #2
0
        public override void Run(ServiceProviderContainer container, Assembly[] assemblies, CrudlessOptions options)
        {
            var universalProfiles = assemblies
                                    .SelectMany(x => x.GetExportedTypes())
                                    .Where(x => !x.IsAbstract &&
                                           x.BaseType != null &&
                                           x.BaseType.IsGenericType &&
                                           x.BaseType.GetGenericTypeDefinition() == typeof(UniversalRequestProfile <>))
                                    .ToArray();

            bool ShouldDecorate(DecoratorConditionalContext context)
            {
                var tRequest = context.ServiceType.GetGenericArguments()[0];

                foreach (var type in tRequest.BuildTypeHierarchyUp())
                {
                    if (type.GetInterface(typeof(ICrudlessRequest).Name) != null)
                    {
                        return(false);
                    }

                    if (universalProfiles.Any(x => x.BaseType.GetGenericArguments()[0] == type))
                    {
                        return(true);
                    }
                }

                return(false);
            }

            container.RegisterDecorator(typeof(IRequestHandler <>), typeof(UniversalRequestDecorator <>), ShouldDecorate);
            container.RegisterDecorator(typeof(IRequestHandler <,>), typeof(UniversalRequestDecorator <,>), ShouldDecorate);
        }
예제 #3
0
 public abstract void Run(ServiceProviderContainer container, Assembly[] assemblies, CrudlessOptions options);
예제 #4
0
        public override void Run(ServiceProviderContainer container, Assembly[] assemblies, CrudlessOptions options)
        {
            var shouldValidate      = ShouldValidate(options.ValidateAllRequests);
            var shouldMaybeValidate = ShouldMaybeValidate(options.ValidateAllRequests);

            container.Register(typeof(IRequestValidator <>), assemblies);

            container.RegisterInstance(new ValidatorFactory(container));

            container.RegisterDecorator(typeof(IRequestHandler <>), ValidatorFactory, shouldValidate);
            container.RegisterDecorator(typeof(IRequestHandler <,>), ValidatorFactory, shouldValidate);

            container.RegisterDecorator(typeof(IRequestHandler <>), typeof(MaybeValidateDecorator <>), shouldMaybeValidate);
            container.RegisterDecorator(typeof(IRequestHandler <,>), typeof(MaybeValidateDecorator <,>), shouldMaybeValidate);
        }
예제 #5
0
        public override void Run(ServiceProviderContainer container, Assembly[] assemblies, CrudlessOptions options)
        {
            container.RegisterInitializer <ICrudlessRequestHandler>(handler =>
            {
                if (handler.ErrorDispatcher.Handler == null)
                {
                    handler.ErrorDispatcher.Handler = container.ProvideInstance <IErrorHandler>();
                }
            });

            container.RegisterSingleton <IErrorHandler, ErrorHandler>();
        }
예제 #6
0
 public override void Run(ServiceProviderContainer container, Assembly[] assemblies, CrudlessOptions options)
 {
     if (_mapper != null)
     {
         using (var scope = container.AllowOverrides())
             container.RegisterInstance(_mapper);
     }
 }
예제 #7
0
 public override void Run(ServiceProviderContainer container, Assembly[] assemblies, CrudlessOptions options)
 {
     container.Register <IMediator>(() => new DynamicDispatchMediator(container, ScopeRequests));
 }