private void AddRepositories(Assembly assembly, ResourceDescriptor resourceDescriptor) { foreach (var serviceInterface in RepositoryInterfaces) { RegisterServiceImplementations(assembly, serviceInterface, resourceDescriptor); } }
/// <summary> /// Attempts to get a descriptor of the resource type. /// </summary> /// <returns> /// True if the type is a valid json:api type (must implement <see cref="IIdentifiable"/>), false otherwise. /// </returns> internal static bool TryGetResourceDescriptor(Type type, out ResourceDescriptor descriptor) { if (type.Implements <IIdentifiable>()) { descriptor = new ResourceDescriptor(type, GetIdType(type)); return(true); } descriptor = ResourceDescriptor.Empty; return(false); }
/// <summary> /// Attempts to get a descriptor of the resource type. /// </summary> /// <returns> /// True if the type is a valid json:api type (must implement <see cref="IIdentifiable"/>), false otherwise. /// </returns> internal static bool TryGetResourceDescriptor(Type type, out ResourceDescriptor descriptor) { var possible = GetIdType(type); if (possible.isJsonApiResource) { descriptor = new ResourceDescriptor(type, possible.idType); return(true); } descriptor = ResourceDescriptor.Empty; return(false); }
private void RegisterResourceDefinition(Assembly assembly, ResourceDescriptor identifiable) { try { var resourceDefinition = TypeLocator.GetDerivedGenericTypes(assembly, typeof(ResourceDefinition <>), identifiable.ResourceType) .SingleOrDefault(); if (resourceDefinition != null) { _services.AddScoped(typeof(ResourceDefinition <>).MakeGenericType(identifiable.ResourceType), resourceDefinition); } } catch (InvalidOperationException e) { throw new JsonApiSetupException($"Cannot define multiple ResourceDefinition<> implementations for '{identifiable.ResourceType}'", e); } }
private void RegisterResourceDefinition(Assembly assembly, ResourceDescriptor identifiable) { try { var resourceDefinition = TypeLocator.GetDerivedGenericTypes(assembly, typeof(ResourceDefinition <>), identifiable.ResourceType) .SingleOrDefault(); if (resourceDefinition != null) { _services.AddScoped(typeof(ResourceDefinition <>).MakeGenericType(identifiable.ResourceType), resourceDefinition); } } catch (InvalidOperationException e) { // TODO: need a better way to communicate failure since this is unlikely to occur during a web request throw new JsonApiException(500, $"Cannot define multiple ResourceDefinition<> implementations for '{identifiable.ResourceType}'", e); } }
private void AddResourceToGraph(ResourceDescriptor identifiable, IResourceNameFormatter resourceNameFormatter = null) { var resourceName = FormatResourceName(identifiable.ResourceType, resourceNameFormatter); _graphBuilder.AddResource(identifiable.ResourceType, identifiable.IdType, resourceName); }
private void RegisterServiceImplementations(Assembly assembly, Type interfaceType, ResourceDescriptor resourceDescriptor) { if (resourceDescriptor.IdType == typeof(Guid) && interfaceType.GetTypeInfo().GenericTypeParameters.Length == 1) { return; } var genericArguments = interfaceType.GetTypeInfo().GenericTypeParameters.Length == 2 ? new[] { resourceDescriptor.ResourceType, resourceDescriptor.IdType } : new[] { resourceDescriptor.ResourceType }; var service = TypeLocator.GetGenericInterfaceImplementation(assembly, interfaceType, genericArguments); //if(service.implementation?.Name == "CustomArticleService" && genericArguments[0].Name != "Article") //{ // service = TypeLocator.GetGenericInterfaceImplementation(assembly, interfaceType, genericArguments); //} if (service.implementation != null) { _services.AddScoped(service.registrationInterface, service.implementation); } }
private void AddResourceToGraph(ResourceDescriptor identifiable) { _resourceGraphBuilder.AddResource(identifiable.ResourceType, identifiable.IdType); }
private void AddResource(Assembly assembly, ResourceDescriptor resourceDescriptor) { RegisterResourceDefinition(assembly, resourceDescriptor); AddResourceToGraph(resourceDescriptor); }
private void AddResource(Assembly assembly, ResourceDescriptor resourceDescriptor) { RegisterResourceDefinition(assembly, resourceDescriptor); _resourceGraphBuilder.AddResource(resourceDescriptor.ResourceType, resourceDescriptor.IdType); }
private void RegisterServiceImplementations(Assembly assembly, Type interfaceType, ResourceDescriptor resourceDescriptor) { var genericArguments = interfaceType.GetTypeInfo().GenericTypeParameters.Length == 2 ? new [] { resourceDescriptor.ResourceType, resourceDescriptor.IdType } : new [] { resourceDescriptor.ResourceType }; var service = TypeLocator.GetGenericInterfaceImplementation(assembly, interfaceType, genericArguments); if (service.implementation != null) { _services.AddScoped(service.registrationInterface, service.implementation); } }