static (object instance, MethodInfo method) GetMethodAndInstanceOfType(string typeName, string methodName) { var type = _typeFinder.FindTypeByFullName(typeName); var instance = _container.Get(type); var method = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public); return(instance, method); }
public IRecipe GetByName(RecipeType name) { var typeName = $"{typeof(RecipeLocator).Namespace}.Recipes.{name}"; var type = _typeFinder.FindTypeByFullName(typeName); var recipe = Activator.CreateInstance(type) as IRecipe; return(recipe); }
/// <summary> /// Get the type of the query matching the fullname. This can be in any loaded assembly and does not require the assmebly qualified name. /// </summary> /// <param name="typeFinder">instance of <see cref="ITypeFinder"/> being extended.</param> /// <param name="fullName">The full name of the type.</param> /// <returns>the type if found, <see cref="UnknownQuery" /> if not found or type is not a query.</returns> public static Type GetQueryTypeByName(this ITypeFinder typeFinder, string fullName) { var queryType = typeFinder.FindTypeByFullName(fullName); if (queryType?.HasInterface(typeof(IQuery)) != true) { throw new UnknownQuery(fullName); } return(queryType); }
/// <summary> /// Get the type of the <see cref="IReadModelOf{T}"/> matching the fullname. This can be in any loaded assembly and does not require the assmebly qualified name. /// </summary> /// <param name="typeFinder">instance of <see cref="ITypeFinder"/> being extended</param> /// <param name="fullName">The full name of the type</param> /// <returns>the type if found, <see cref="UnknownReadModelOfException" /> if not found or type is not a readmodelof</returns> public static Type GetReadModelOfTypeByName(this ITypeFinder typeFinder, string fullName) { var readModelOfType = typeFinder.FindTypeByFullName(fullName); if (readModelOfType == null || !readModelOfType.HasInterface(typeof(IReadModelOf <>))) { throw new UnknownReadModelOfException(fullName); } return(readModelOfType); }
/// <summary> /// Get the type of the command matching the fullname. This can be in any loaded assembly and does not require the /// </summary> /// <param name="typeFinder">instance of <see cref="ITypeFinder"/> being extended</param> /// <param name="fullName">The full name of the type</param> /// <returns>the type if found, <see cref="UnknownCommandException" /> if not found or type is not a command</returns> public static Type GetCommandTypeByName(this ITypeFinder typeFinder, string fullName) { var commandType = typeFinder.FindTypeByFullName(fullName); if (commandType == null || !commandType.HasInterface(typeof(ICommand))) { throw new UnknownCommandException(fullName); } return(commandType); }
/// <summary> /// Get the type of the query matching the fullname. This can be in any loaded assembly and does not require the assmebly qualified name. /// </summary> /// <param name="typeFinder">instance of <see cref="ITypeFinder"/> being extended</param> /// <param name="fullName">The full name of the type</param> /// <returns>the type if found, <see cref="UnknownQueryException" /> if not found or type is not a query</returns> public static Type GetQueryTypeByName(this ITypeFinder typeFinder, string fullName) { var queryType = typeFinder.FindTypeByFullName(fullName); if (queryType == null || !queryType.HasInterface(typeof(IQuery))) { throw new UnknownQueryException(fullName); } return(queryType); }
/// <summary> /// Get the type of the <see cref="IReadModelOf{T}"/> matching the fullname. This can be in any loaded assembly and does not require the assmebly qualified name. /// </summary> /// <param name="typeFinder">instance of <see cref="ITypeFinder"/> being extended.</param> /// <param name="fullName">The full name of the type.</param> /// <returns>the type if found, <see cref="UnknownReadModelOf" /> if not found or type is not a readmodelof.</returns> public static Type GetReadModelOfTypeByName(this ITypeFinder typeFinder, string fullName) { var readModelOfType = typeFinder.FindTypeByFullName(fullName); if (readModelOfType?.HasInterface(typeof(IReadModelOf <>)) != true) { throw new UnknownReadModelOf(fullName); } return(readModelOfType); }
public virtual Type GetServerTypeFrom(string fullyQualifiedClientName) { var mappers = _clientToServerMapper.GetAllMatchingMappingsFor(fullyQualifiedClientName); foreach (var mapper in mappers) { var fullyQualifiedName = mapper.Resolve(fullyQualifiedClientName); var matchingType = _typeFinder.FindTypeByFullName(fullyQualifiedName); if (matchingType != null) { return(matchingType); } } return(null); }
public object InstanceMatching(ReadModelQueryDescriptor descriptor) { var readModelType = _typeFinder.FindTypeByFullName(descriptor.GeneratedFrom); if (readModelType != null) { var readModelOfType = typeof(IReadModelOf <>).MakeGenericType(readModelType); var readModelOf = _container.Get(readModelOfType); var instanceMatchingMethod = readModelOfType.GetMethod("InstanceMatching"); var genericAuthorizeMethod = _authorizeMethod.MakeGenericMethod(readModelType); var authorizationResult = genericAuthorizeMethod.Invoke(_fetchingSecurityManager, new[] { readModelOf }) as AuthorizationResult; if (!authorizationResult.IsAuthorized) { return(null); } var funcType = typeof(Func <,>).MakeGenericType(readModelType, typeof(bool)); var expressionType = typeof(Expression <>).MakeGenericType(funcType); var expressions = Array.CreateInstance(expressionType, descriptor.PropertyFilters.Count); var index = 0; foreach (var key in descriptor.PropertyFilters.Keys) { var expression = GetPropertyEqualsExpression(readModelType, key.ToPascalCase(), descriptor.PropertyFilters[key]); expressions.SetValue(expression, index); index++; } var result = instanceMatchingMethod.Invoke(readModelOf, new[] { expressions }); var filtered = _readModelFilters.Filter(new[] { result as IReadModel }); if (filtered.Count() == 1) { return(filtered.First()); } } return(null); }
public Type FindTypeByFullName(string fullName) { return(_typeFinder.FindTypeByFullName(_contractToImplementorsMap, fullName)); }