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

[Proposal] Add shared interfaces to identify ids #63

Open
hankovich opened this issue Apr 4, 2022 · 1 comment
Open

[Proposal] Add shared interfaces to identify ids #63

hankovich opened this issue Apr 4, 2022 · 1 comment

Comments

@hankovich
Copy link

I suggest to add an additional project (StronglyTypedId.Interfaces) with

public interface IId<TBacking>
{
    TBacking Value { get; }
}

and probably with

public interface IId<TId, TBacking>
    where TId : IId<TId, TBacking>
{
    static abstract TId New();

   // Parse/TryParse
}

IId interfaces will drammatically help us to minimize boilerplate code:

  1. Ids are stored in redis (and in rdbms via dapper) and we write the same (de)serialization code again and again, shared Parse/TryParse will help here
  2. We configure swagger to treat ids as guids and we have to explicitely enumerate all ids during configuration. With IId in place it will be possible to enumerate all ids via reflection.

We store ids in separate libraries with contracts and we do not to pollute ids with additional attributes or add swagger/dapper packages to contract libraries.

@andrewlock
Copy link
Owner

I'm on board with the interface as an optional extra (though I think you could do this now relatively easily?) but I'm not sure about the extra project 🤔 If you need the interface to be in a separate project from the IDs then I think your best bet is to write those yourselves, and then just add them to your ID definitions e.g.

[StronglyTypedId]
public partial struct MyId : IId<MyId , Guid> {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants