vendredi 24 novembre 2017

Restrict access to a specific assembly c#

I'm working on a Winforms project with sql server, splitted in several assemblies.

The first assembly Entities contains DTO like :

public class Attribution
{
    public short UserId { get; set; }
    public User User { get; set; }
}
public class User
{
    public short Id { get; set; }
}

The second assembly Repository is accessing Sql Server database.

The third assembly Service is the link between previous.

There are other layers but this is not the point. I need of course DTO's everywhere in the app.

In sql server, Attribution.UserId and User.Id are the same datas, located in 2 separate tables, linked by Ìnner join.

Attribution.UserId must be public because I need access from Repository,Service, etc... But I don't need it in the "logical" part of the app, what I need is Attribution.User.

At this time I have a UserService class in which there is a GetUser() method and I call this method to get the user in my AttributionService.GetAttribution() method.

Is there a way to restrict access to Attribution.UserId property to Service assembly? Or is it a kind of "good practice violation" to query a User DTO in AttributionService class?

Many thanks for your recommandation.

`

Aucun commentaire:

Enregistrer un commentaire