Better Code Encapsulation Support

4 posts, 0 answers
  1. Bryson Lafferty
    Bryson Lafferty avatar
    2 posts
    Member since:
    Oct 2012

    Posted 23 Oct 2012 Link to this post

    I have been using Telerik OpenAccess for years now, and one frustrating issue is the inability for good code encapsulation from generated object classes to enforce business rules within the domain to throw exceptions, etc when necessary using the designers rather than going completely to fluid mapping.  It would be great if we had more control in the entities designer to control how properties are generated in mapped class.  I have have even tried to create my own code generation templates which ultimately creates more of a headache then helps.  Partial classes are a good start, but we cannot enforce business rules with generated properties or encapsulate logic in our data layer.  I'm aware of the fluent mapping support, but this is more work than we are prepared for.

    Right now if we select the storage behavior to PersistentReadOnly or PersistendWriteOnly, it affects the properties generated which is great, but it also throws an exception if we try and set the private fields manually through our own custom methods.  It would be great if setting this behavior controlled the code generation only, but still allowed us to set these fields.  That, or some additional storage behavior options or an actual implementation of the CustomBehavior which we have been waiting for for a while now?

    This seems like it would be an fairly easy modification/feature to add... I'm hoping you will consider this in your next release.

    Thank you!

  2. Ivailo
    Admin
    Ivailo avatar
    318 posts

    Posted 26 Oct 2012 Link to this post

    Hi Bryson,

    I understand the need of more flexibility in our code generation and in fact we are already discussing possible improvements there.

    Currently the best way you can customize your code generation is updating the templates we provide, but you are right that this is not an easy task. One of the possible future steps in this direction is for us to provide more guidance how to achieve that. Another one is to directly deploy additional templates for the most common scenarios. For this improvement it will be really helpful if you can share with us a sample class with some business logic in the way that you would like to see it generated. In case you can share such class I will convert the thread into a feedback ticket so that you can attach items.

    Regarding the storage behavior, have in mind that this is setting for the runtime behavior rather than code generation behavior. Unfortunately it will not help you achieve what you want. The right way would be to customize the access modifiers and implement some logic. From our side I can note down a feature request for providing another option for customizing whether the property should have a getter and a setter. I hope this would help?

    I am looking forward to your feedback.

    All the best,
    Ivailo
    the Telerik team
    Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
  3. DevCraft banner
  4. Bryson Lafferty
    Bryson Lafferty avatar
    2 posts
    Member since:
    Oct 2012

    Posted 31 Oct 2012 Link to this post

    Hi Ivailo,

    Thank you for your response.  Even with code generation templates, which I've successfully implemented in some solutions it seems I must make changes to code generation globally (to all generated classes).  If we simply had a few more code generation configuration parameters in the class properties, that would be great.  Some properties we may only want a GET or SET ability and not all of them.  It would be great if we could selectively control this on class properties/fields that we still want persisted.

    I'd be happy to provide an example class if that helps your team, but basically I would love to see a configuration property in the designer to generate either 1) No property, 2) GET only 3) SET only or 4) Both GET/SET and allow us to encapsulate logic ourselves by setting the field manually or through a method and hiding access outside of the data layer to enforce business rules.  I understand that I probably could do this with Fluid Mapping, but it would really save some time being able to use the designer as well as have the flexibility of control of code generation and using associate partial classes.

    Thank you for your help!  Telerik tools rock!
    Bryson
  5. Ivailo
    Admin
    Ivailo avatar
    318 posts

    Posted 06 Nov 2012 Link to this post

    Hello Bryson,

    I think I understand what you need.

    I have created a new feature request in our Public Issue Tracking System based on your feedback. There you can vote for the feature and other people can do the same so that its priority for implementation will raise with each vote. 

    Do not hesitate to get back to us if you have any other feature requests.

    All the best,
    Ivailo
    the Telerik team
    Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
Back to Top