7digital / SevenDigital.Api.Wrapper

A fluent c# wrapper for the 7digital API
MIT License
16 stars 29 forks source link

Api creation #179

Closed AnthonySteele closed 10 years ago

AnthonySteele commented 10 years ago

Addressing api creation issues as per https://github.com/7digital/SevenDigital.Api.Wrapper/issues/169. There is an IApi interface and a default implementation.

The example usage program shows the simple case usage,

ie.

    IApi api = new ApiFactory();
    var artist = await api.Create<Artist>()
        .WithArtistId(artistId)
        .Please();

    var artistTopTracks = await api.Create<ArtistTopTracks>()
        .WithArtistId(artistId)
        .Please();

The advantage is that api is an instance of type IApi so it is injectable, and you can make multiple independent request of the same or varying types off it using IFluentApi<T> request = api.Create<T>() multiple times. If you follow this pattern, you should have no more concurrency issues.

A Customised usage is for the api user to make their own implementation of IApi supplying creds etc. This is not hard, See here for an example

The static generic Api class with a Create property is retained for compatibility, tests, very simple cases and for consumers who like global singletons :/ but it can now be forwarded to a custom IApi Example as above. I removed the static CreateWithCreds method as the forwarding is the extension point - we don't want to encourage use of this class in more complex cases.