/// <summary> /// Enables code-based conventions for a domain. /// </summary> /// <param name="configuration"> /// A domain configuration. /// </param> /// <param name="targetType"> /// The type of a class on which code-based conventions are used. /// </param> /// <remarks> /// This method adds hook points to the domain configuration that /// inspect a target type for a variety of code-based conventions /// such as usage of specific attributes or members that follow /// certain naming conventions. /// </remarks> public static void EnableConventions( this DomainConfiguration configuration, Type targetType) { Ensure.NotNull(configuration, "configuration"); Ensure.NotNull(targetType, "targetType"); ConventionalChangeSetAuthorizer.ApplyTo(configuration, targetType); ConventionalChangeSetEntryFilter.ApplyTo(configuration, targetType); configuration.AddHookPoint(typeof(IChangeSetEntryValidator), ConventionalChangeSetEntryValidator.Instance); ConventionalEntitySetProvider.ApplyTo(configuration, targetType); ConventionalModelExtender.ApplyTo(configuration, targetType); ConventionalEntitySetFilter.ApplyTo(configuration, targetType); }
/// <inheritdoc/> public Task <bool> AuthorizeAsync( SubmitContext context, ChangeSetEntry entry, CancellationToken cancellationToken) { Ensure.NotNull(context); bool result = true; Type returnType = typeof(bool); string methodName = ConventionalChangeSetAuthorizer.GetAuthorizeMethodName(entry); MethodInfo method = this.targetType.GetQualifiedMethod(methodName); if (method != null && method.IsPrivate && method.ReturnType == returnType) { object target = null; if (!method.IsStatic) { target = context.DomainContext.GetProperty( this.targetType.AssemblyQualifiedName); if (target == null || !this.targetType.IsAssignableFrom(target.GetType())) { return(Task.FromResult(result)); } } var parameters = method.GetParameters(); if (parameters.Length == 0) { result = (bool)method.Invoke(target, null); } } return(Task.FromResult(result)); }