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); }
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); }
public abstract void Run(ServiceProviderContainer container, Assembly[] assemblies, CrudlessOptions options);
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); }
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>(); }
public override void Run(ServiceProviderContainer container, Assembly[] assemblies, CrudlessOptions options) { if (_mapper != null) { using (var scope = container.AllowOverrides()) container.RegisterInstance(_mapper); } }
public override void Run(ServiceProviderContainer container, Assembly[] assemblies, CrudlessOptions options) { container.Register <IMediator>(() => new DynamicDispatchMediator(container, ScopeRequests)); }