Ahmed Okour
Ahmed Okour

Reputation: 2422

Extending properties of common library

We are developing a product for different customers (ASP.NET solution), the solution consists of 3 VS projects, Business Entities, Business Services and Web. Each customer might need some customization, so we will need to make some changes on these 3 project.

Business entities project contains classes with properties only, and Business Services contains classes with methods only and these methods use Business Entities classes.

My problem is that i don't want to duplicate these 2 projects (Entities, Services) for each customer since they will have almost the same code.

I thought about making Entities and Services as common library, and reference them in each new solution, and if customer needs some customization, i can extend these two library.

Extension Methods helped me to extend 'Business Services' classes, but for 'Business Entities' classes i could not find a good solution to extend its properties, There is no Extension Properties in .NET.

I thought about making partial classes, but i don't know if this is a good practice.

Does anyone have a better solution?

Upvotes: 0

Views: 82

Answers (1)

Avitus
Avitus

Reputation: 15958

If you make your properties be "virtual" then you can override them based on the client needs. That way you don't have to go down the path of making partial classes.

Here's the link to the info on making things be "virtual"

Upvotes: 1

Related Questions