1

So I have a architecture with several distinct 'back-end' asp.net core web api's. I am using Masstransit and rabbitmq to facilitate inter-container communication. With MassTransit, the services need a sort of contract between them (just simple classes), which if the system is deployed locally or on a server is fine, but with docker containers this is has proven to be a problem.

I have tried googling a lot, but there seems to be very little asp.net core, and especially masstransit, combined with docker documentation.

So question is:

How do I have to separate containers, written with asp.net core, share messaging contracts (i.e. model classes)?

I thought about creating a nugget package. This would work, but it seems like a pretty inelegant solution + contracts would be public (not a big deal, but still probably not great).

lastly, i orchestrate the services with docker-compose - if that has relevance for your answer.

1 Answer 1

0

If the projects are in separate GitHub repositories, and you need to share contracts, you have a few options.

  1. Create a separate repository, publish it as a NuGet package. You can do this privately, using GitHub package repository, so that your contracts are not on the public NuGet site. This gives you a single place, but becomes a single point of contention for message contracts. Good: It's easy, and contracts should not change, and new versions should be designed with backwards compatibility as not all services will upgrade to the latest.

  2. Copy the classes (though I personally prefer interfaces, but that's another story) into your project – exactly, including the namespace. Some OCD people freak out about this, but honestly, are we doing anything different with JSON and HTTP? If contracts are managed well, and the owners exhibit control in ensuring they're consistent and compatible, this works. And I've seen it done. I will repeat, however, the namespace much match, not just the class/interface name.

Those are the two approaches I've used, both with great success. I've heard of some teams using a single repository with folders for each service. Makes sense, modern CI/CD can track path changes and only build/deploy the modified services. So I guess that's a third option, instead of creating a myriad of repositories for closely-coupled services.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I was thinking something along these lines, but I have no experience in this, so did not know if it was an allright way of doing it. I will do just as you suggest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.