I'm starting large project and I want use DDD. The main problem is how to display data from multiple Bounded Context without duplicating data and mappings of NH. I watched Udi's podcast about composite application. He mention about using Razor sections to display data from multiple bounded contexts but he doesn't provide any details. Does anybody know how to use it or does anybody know other way?
-
The first step is to partition the application into subsystems. The core of the application containing the business rules can be implemented in a subsystem, the UI in another, and the database in yet another. Once each subsystem is completed, you can build "bridges" between them, using well-defined message formats. "Subsystems" are analogous to "bounded contexts". – Jun 06 '12 at 12:16
-
1@jeyoung: What you calling 'Subsystem' is also known as 'Layer'. Layer is not the same as Bounded Context. Bounded contexts divide system vertically, Layers divide them horizontally. – Dmitry Jun 07 '12 at 04:08
-
Subsystems are domains. See http://ooatool.blogspot.co.uk/2008/09/subsystem-communication-model-notation.html. – Jun 08 '12 at 11:37
2 Answers
Good thing about Razor is that it allows you to have completely independent controllers that are responsible for rendering parts of the single page (portal style). For example in your main Razor view:
<some_markup> New products </some_markup>
@{ Html.RenderAction("Get", "NewProducts"); }
<some_markup> Product ratings </some_markup>
@{ Html.RenderAction("Get", "ProductRatings"); }
Where NewProductsController
and ProductRatingsController
belong to different Bounded Contexts and look like this:
public class NewProductsController {
private readonly IProducts repository;
public NewProductsController(IProducts repository) {
...
}
[ChildActionOnly]
public ViewResult Get() {
// load products from repository and
// return corresponding ViewModel
}
}
public class ProductRatingsController {
private readonly IProductRatings repository;
public ProductRatingsController(IProductRatings repository) {
...
}
[ChildActionOnly]
public ViewResult Get() {
// load product ratings from repository and
// return corresponding ViewModel
}
}
Note that controllers don't know about each other although they will display data on the same page. The repositories can be injected using DI container in the Composition Root of your application.
-
So the user interface accesses multiple contexts, and in which context does the user interface reside ?, In your example where would the view reside ? – Sudarshan Sep 28 '14 at 15:35
-
@Sudarshan Restricting the user interface into one single context will prohibit you from creating it to be informative and user friendly. The idea of the bounded context is to isolate most of the business rules and logic. UI does not need to be as isolated, as merging on that level will not create system wide cohesion that would degrade maintainability. – Tuukka Haapaniemi Jun 30 '15 at 12:35
In regards to NH mappings, each bounded context (BC) should have its own set of mappings and therefore its own session factory. It can be tricky to configure a DI container such that it resolves the appropriate session factory for each respective BC, because the session factory interface will have to be "tagged" to be associated with a particular BC and then all dependencies within that BC will also have to be associated with that tag. Another option is to create a open host service (such as REST) to encapsulate each BC and then reference the service from your web app. This way you don't have to worry about managing NH mappings in your web application.

- 36,769
- 7
- 61
- 83