I have a requirement where I need to host the same website in 2 domains. The only differences between the 2 are minor style differences (basically just the logo and the header), where the site will be hosted and the connection string for the database (the db structure is going to be the same).
I suppose this is roughly a similar requirement to the different stackexhange websites.
What is the best way to create and maintain this? I want to avoid having 2 complete separate solutions as that will become a maintenance nightmare. There is a slight chance that enhancements may need to be made to the 2 sites seperately.
My project structure is roughly as follows:
- Web Project (asp.net web forms)
- Data Project (EF for data access)
- Services Project (for returning data from data layer and processing any calculations)
This is the way I was thinking of doing it:
- Have logic in the web project that will display different styles depending on where it is accessed from.
- Have separate service classes for the 2 domains with different connection strings. This will mean alot of duplicated code in the service layer.
- Use dependency injection where I can easily change which service class is going to be used at deployment time.
Something like
aspx:
<% if(domain) { %>
some html
<% } %>
aspx.cs:
[Inject]
public IService service { get; set; }
IService.cs:
public interface IService
{
string GetClients();
}
Service.cs:
public class DomainAService: IService
{
DbContext db = new DbContext("connectionStringA");
public string GetClients()
{
return db.Clients.ToString();
}
}
public class DomainBService: IService
{
DbContext db = new DbContext("connectionStringB");
public string GetClients()
{
return db.Clients.ToString();
}
}
Does this architecture make sense? Is the duplicated logic in the service layer a problem? I wonder how the stack exchange sites do it.