Skip to content
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

Support dependency-injection #66

Open
goofballLogic opened this issue Jul 5, 2020 · 3 comments
Open

Support dependency-injection #66

goofballLogic opened this issue Jul 5, 2020 · 3 comments
Milestone

Comments

@goofballLogic
Copy link
Member

The normal usage pattern for the library is to use the static JsonLdProcessor class. This works well for the stateless, static algorithms which make up the JSON-LD standard. However, it requires a consumer to create an injectable facade class in order to inject the APIs into consumers. e.g.

interface IJsonLdProcess {
    JObject Compact(JToken input, JToken context, JsonLdOptions opts);
}

class JsonLdProcess {
    JObject Compact(JToken input, JToken context, JsonLdOptions opts) {
        return JsonLdProcessor.Compact(input, context, opts);
    }
}

public class Consumer {

    private readonly JToken _context;
    private readonly IJsonLdProcess _jsonLdProcess;

    public Consumer(IJsonLdProcess jsonLdProcess, JToken context) {
        _jsonLdProcess = jsonLdProcess;
        _context = context;
    }

    public JObject Execute(JObject input) =>
        _jsonLdProcess.Compact(input, _context);
    }
}

Can we provide the functionality exposed by JsonLdProcessor as a non-static implementation of an interface which can be mocked for purposes of unit testing / decoration.

@asbjornu
Copy link
Member

asbjornu commented Jul 5, 2020

interface IJsonLdProcess {
    JObject Compact(JToken input, JToken context, JsonLdOptions opts);
}

This interface would require a dependency on Json.NET, so I would prefer a signature that only dealt with objects we defined in our own Core. Something like this:

interface ILinkedDataProcessor
{
    LinkedDataObject Compact(LinkedDataObject input, LinkedDataContext context, LinkedDataOptions options);
}

This would make the Core to be dependency-free and allow Json.NET, System.Text.Json, Turtle, and possibly other serializations as ancillary projects to the Core.

@goofballLogic
Copy link
Member Author

Agreed. I was not proposing an exact interface here. I also think that we should allow that #66 and #65 might be implemented in either order since we are evolving the codebase

@stale
Copy link

stale bot commented Oct 3, 2020

This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 3, 2020
@goofballLogic goofballLogic added this to the 2.0.0 milestone Oct 5, 2020
@stale stale bot removed the stale label Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants