Beispiel #1
0
        public void Run(Container container, Assembly[] assemblies, CrudOptions 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(DecoratorPredicateContext context)
            {
                var tRequest = context.ServiceType.GetGenericArguments()[0];

                foreach (var type in tRequest.BuildTypeHierarchyUp())
                {
                    if (type.GetInterface(typeof(ICrudRequest).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);
        }
Beispiel #2
0
        public void Run(Container container, Assembly[] assemblies, CrudOptions options)
        {
            bool IfNotHandled(PredicateContext c) => !c.Handled;

            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);
        }
Beispiel #3
0
        public void Run(Container container, Assembly[] assemblies, CrudOptions options)
        {
            container.RegisterInitializer <ICrudRequestHandler>(handler =>
            {
                if (handler.ErrorDispatcher.Handler == null)
                {
                    handler.ErrorDispatcher.Handler = container.GetInstance <ICrudErrorHandler>();
                }
            });

            container.Register(typeof(ICrudErrorHandler), typeof(CrudErrorHandler), Lifestyle.Singleton);
        }
Beispiel #4
0
        public void Run(Container container, Assembly[] assemblies, CrudOptions options)
        {
            var shouldValidate      = ShouldValidate(options.ValidateAllRequests);
            var shouldMaybeValidate = ShouldMaybeValidate(options.ValidateAllRequests);

            container.RegisterInstance(new ValidatorFactory(container.GetInstance));

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

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

            container.RegisterDecorator(typeof(IRequestHandler <>), typeof(CrudMaybeValidateDecorator <>), shouldMaybeValidate);
            container.RegisterDecorator(typeof(IRequestHandler <,>), typeof(CrudMaybeValidateDecorator <,>), shouldMaybeValidate);
        }