Skip to content

bounded contexts

vijay@envivo edited this page Jul 11, 2024 · 10 revisions

Bounded Contexts

Ideally, each Bounded Context (BC) is mapped to a single .NET assembly (i.e. .NET project). For simpler models, you probably only need a single assembly.

Step 1: Open your Domain Model project

Step 2: Add a reference to each of your domain assemblies:

Step 3: Register each domain assembly in your bootstrapper code using WithModelAssembly:

...

var typeFromBoundedContext1 = typeof(Acme.OnlineShopping.CustomerAccounts.Customer);
var typeFromBoundedContext2 = typeof(SampleModelForDocs.BasicPropertyTypes);

var builder = new HostApplicationBuilder(args);

builder.AddFresnel(opt =>
{
    opt
	.WithModelAssembly(typeFromBoundedContext1.Assembly) //👈
	.WithModelAssembly(typeFromBoundedContext2.Assembly) //👈
	...
    ;
});

💡 Developer Tips

Try to keep things simple

When starting out, consider using just a single assembly to keep things simple and fast. Use separate namespaces for each BC. Refactor into multiple assemblies when the domain model gets larger and more complicated.

Watch out for dependencies between Bounded Contexts

Refrain from creating dependencies between your BCs/assemblies. If you discover dependencies between them, you may need a messaging system to handle the communications (possibly using messages buses and/or microservices)

Fresnel does not include a messaging mechanism, so try libraries such as MediatR to simulate the communications.

Clone this wiki locally