Skip to content

Auto-Resource, Repository, and Service Discovery #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jaredcnance opened this issue Mar 9, 2018 · 1 comment · Fixed by #376
Closed

Auto-Resource, Repository, and Service Discovery #241

jaredcnance opened this issue Mar 9, 2018 · 1 comment · Fixed by #376

Comments

@jaredcnance
Copy link
Contributor

jaredcnance commented Mar 9, 2018

We should be able to reflect on the assembly and auto discover all implementations of IIdentifiable<,>, IResourceService<,>, IEntityRepository<,> adding them to the ContextGraph. A possible API might look like:

public void ConfigureServices(IServiceCollection services)
{
    services.AddJsonApi(options => 
        options.BuildContextGraph((builder) => 
            builder.AddAssembly(/*...*/);
        );
    );
}

We may also expose the following for finer control:

builder.AddAssemblyResources(/* ... */); // should also register ResourceDefinitions
builder.AddAssemblyServices(/* ... */);
builder.AddAssemblyRepositories(/* ... */);

This work may include improved handling for multiple database contexts. See #269. In order to automatically handle multiple contexts, we need a way to specify that FooRepository depends on BarDbContextResolver at startup. Currently, I don't think Microsoft's DI library provides anything with that level of registration. We could consider providing a separate package that depends on Autofac (for example) where we explicitly construct the dependency graph.

jaredcnance added a commit that referenced this issue Jul 5, 2018
fix(AttrAttribute): unexpected scenarios cause breaking change
jaredcnance added a commit that referenced this issue Jul 5, 2018
specify symbols server for develop
@jaredcnance
Copy link
Contributor Author

jaredcnance commented Aug 12, 2018

v3.0.0-beta Notes

We need help from you: if you’re interested in helping get this feature fully released, download the 3.0.0-beta version(s) and provide feedback in this issue or you can open a new issue for bug reports. Thanks!!

Public Resource Name Resolution

  • Check class definition for attribute [Resource("models"]
[Resource("models"] public class Model : Identifiable { /* ... */ }
  • Check DbSet for attribute (will probably deprecate this in the future)
[Resource("models")] public DbSet<Model> Models { get; set; }
  • Check for IResourceNameFormatter

  • Fallback to dasherized

TODO

  • Improve DX around IResourceNameFormatter. Currently manually passed into ServiceDiscoveryFacade and ContextGraphBuilder...It should only be specified once. Maybe we should just locate it in the ServiceDiscoveryFacade ?

Known Bug List

  • Fixed in v3.0.0-beta2
Unhandled Exception: System.InvalidOperationException: JsonApiDotNetCore.Data.IEntityRepository`2[TodoListAPI.Models.TodoItem,System.Int32] is not a GenericTypeDefinition. MakeGenericType may only be called on a type for which Type.IsGenericTypeDefinition is true.
   at System.RuntimeType.MakeGenericType(Type[] instantiation)
   at JsonApiDotNetCore.Graph.TypeLocator.GetGenericInterfaceImplementation(Assembly assembly, Type openGenericInterfaceType, Type[] genericInterfaceArguments) in C:\projects\jsonapidotnetcore\src\JsonApiDotNetCore\Graph\TypeLocator.cs:line 88
   at JsonApiDotNetCore.Graph.ServiceDiscoveryFacade.RegisterServiceImplementations(Assembly assembly, TypeinterfaceType) in C:\projects\jsonapidotnetcore\src\JsonApiDotNetCore\Graph\ServiceDiscoveryFacade.cs:line 133
   at JsonApiDotNetCore.Graph.ServiceDiscoveryFacade.AddAssemblyServices(Assembly assembly, IResourceNameFormatter resourceNameFormatter) in C:\projects\jsonapidotnetcore\src\JsonApiDotNetCore\Graph\ServiceDiscoveryFacade.cs:line 44
   at TodoListAPI.Startup.<>c.<ConfigureServices>b__4_1(ServiceDiscoveryFacade discovery) in /Users/jarnance/dev/TodoListExample/TodoListAPI/Startup.cs:line 45
   at JsonApiDotNetCore.Extensions.IServiceCollectionExtensions.AddJsonApi(IServiceCollection services, Action`1 configureOptions, IMvcCoreBuilder mvcBuilder, Action`1 autoDiscover) in C:\projects\jsonapidotnetcore\src\JsonApiDotNetCore\Extensions\IServiceCollectionExtensions.cs:line 71
   at TodoListAPI.Startup.ConfigureServices(IServiceCollection services) in /Users/jarnance/dev/TodoListExample/TodoListAPI/Startup.cs:line 42

jaredcnance added a commit that referenced this issue Aug 13, 2018
fix(#241): TypeLocator bug -- add tests
milosloub pushed a commit to milosloub/JsonApiDotNetCore that referenced this issue Sep 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

1 participant