Reputation: 223
I have a dilemma how to organise my new project.
At the moment, I have a magazine style website coded in MVC C# where every page has an own controller with a set of views. Behind controllers, we have a service layer (as a separate project) for accessing to database. Majority of the business logic is in service layer with some bits of the business logic in controllers
We're planning to launch a new website which is going to use a copy of the 1st site database, with 95% the same features as the first website but completely different views/css.
We have a really tight deadline and we want to reuse as much as possible of the existing code and to make both sites super easy to maintain.
As far as I can see we have two options:
To create a new project for the 2nd website, where we will need to re-write all controllers from scratch
To add a new set of views to the existing website and based on a configuration switch to show different views based on the url of the 1st or 2nd site.
1st approach is much cleaner but at also it will generate loads of repeated code and probably a maintenance nightmare.
2nd approach will use the same controllers (with potentially doubled methods for 5% of different functionalities).
Is there 3rd of doing this?
thanks
Upvotes: 2
Views: 582
Reputation: 223
At the end I decided to implement custom views via DisplayMode
DisplayModeProvider.Instance.Modes.Insert(0, new NewSiteDisplayMode()
{
ContextCondition = context => IshkaDisplayMode.IsNewSite(context.Request)
});
Now if I need a custom view for the new website I just create a copy of the existing view add NewSite into name and put specific HTML inside.
Cheers
Upvotes: 2
Reputation: 80
James,
You can use software branching, trunk based development.
Your 2nd approach is smart, where you only have to create new views and rest of your website including business logic, server validations will work like charm.
Infact that is the pure essence of MVC development.
Upvotes: 1
Reputation: 1662
I would use approach 2 if the changes to the business logic are minor and if you can keep it compatible.
There is in fact a third approach, which would be to create a source control branch for v2. You can keep maintaining v1 and integrate the changes to v2 when necessary. Over time however, as your sites drift, these integrations are going to become harder. This approach would thus only be suitable if you have a definite cutoff to get rid of v1.
Depending on the changes to the data model you may need to be able to version your data access code also.
Upvotes: 1