/// <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); }
private Task InvokeFilterMethodAsync( SubmitContext context, ChangeSetEntry entry, string methodNameSuffix) { string methodName = ConventionalChangeSetEntryFilter.GetMethodName(entry, methodNameSuffix); object[] parameters = ConventionalChangeSetEntryFilter.GetParameters(entry); MethodInfo method = this.targetType.GetQualifiedMethod(methodName); if (method != null && (method.ReturnType == typeof(void) || typeof(Task).IsAssignableFrom(method.ReturnType))) { object target = null; if (!method.IsStatic) { target = context.DomainContext.GetProperty( this.targetType.AssemblyQualifiedName); if (target == null || !this.targetType.IsAssignableFrom(target.GetType())) { return(Task.WhenAll()); } } ParameterInfo[] methodParameters = method.GetParameters(); if (ConventionalChangeSetEntryFilter.ParametersMatch(methodParameters, parameters)) { object result = method.Invoke(target, parameters); Task resultTask = result as Task; if (resultTask != null) { return(resultTask); } } } return(Task.WhenAll()); }