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

Generating subentites builders #18

Open
pmrogala opened this issue Jul 30, 2021 · 1 comment
Open

Generating subentites builders #18

pmrogala opened this issue Jul 30, 2021 · 1 comment
Assignees
Labels
draft Not yet finished description enhancement New feature or request XL-size It'll require a lot of work
Milestone

Comments

@pmrogala
Copy link
Owner

pmrogala commented Jul 30, 2021

The golden sample

the source generator should have possibility to generate as follows:
Source:

public class Aggregate
{
     public Entity Entity  { get; set; }
}

public class Entity
{
    /*    */
}


[MakeBuilder(typeof(Aggregate), <NewOption?>)]
[<NewAttribute?>]
public partial class AggregateBuilder
{
}

Output:

public partial class AggregateBuilder
{
     /*    */
}

public partial class EntityBuilder
{
    /*   */
}

Detecting entities to generate builders

Namespace rule

To prevent generating wrongly builders for build-in types, or types from external libraries, the buildenator will detect subentities by the same root namespace of the parent entity.

e.x.
this is correct:

NameSpaceRoot.Aggregate
NameSpaceRoot.SubNamespace.Entity

this is not correct:

NameSpaceRoot.Aggregate
SubNamespace.Entity

Filtering out value types

By default if the subentity has only one not sophisticated property/contr. parameter, it will be treated as a value type, so no additional builders will be created.

Configurability

  • GenereteSubentitiesBuilders[True/False]: whether generating subentities builders [False by default]
    • Should have possibility to set up a global config

Known problems and challenges

  • How to easilly detect whether the entity is simple or not?
  • Secondly, what about reference loop, i.e. one entity having the second one and vice versa?
    • It should be one directional, and it means it'd require to remember what are parent entities and pass them to children.
  • A user should have a possibility to override the subentities builder in a partial class. Probably it'd require an additional marker

For the future

  • A thing to improve in the next iterations - loosen namespace rules, i.e. detect by the number of identifiers taken into the account.
    For example, if the AR has its namespace A.B.C.D, and we set up the number of identifiers to 2, then the generator will generate builders for each entity that has its namespace in the A.B scope.
@pmrogala pmrogala self-assigned this Jul 30, 2021
@pmrogala pmrogala added the draft Not yet finished description label Jul 30, 2021
@pmrogala pmrogala added this to the 4.0.0 milestone Jul 30, 2021
@pmrogala pmrogala added the enhancement New feature or request label Jul 30, 2021
@pmrogala pmrogala modified the milestones: 4.0.0, 3.2.0 Jul 30, 2021
@pmrogala pmrogala modified the milestones: 3.2.0, 4.0.0 Sep 17, 2021
@pmrogala pmrogala modified the milestones: 4.0.0, Future Oct 1, 2021
@pmrogala pmrogala added XL-size It'll require a lot of work and removed XL-size It'll require a lot of work labels Oct 27, 2022
@pmrogala
Copy link
Owner Author

To start simple - an entity is simple when has only one property/field.
It's a false assumption, because this one property may be of a type that is sophisticated itself, but it'll be easy to implement and should cover most of the cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
draft Not yet finished description enhancement New feature or request XL-size It'll require a lot of work
Projects
None yet
Development

No branches or pull requests

1 participant