Load object from multiple datasources with hexagonal architecture (ports and adapters)
up vote
0
down vote
favorite
Description
I'm working with a almost 40 year old project with a lot of legacy code. Over the years multiple databases where added. Now I am converting it step by step to the hexagonal architecture with ports and adapters.
Until now I always created 1 adapter per database. But doing so with this code will give me a representation of my databasestructure in my domain (which I don't want).
Example
If I have a Product object in my domain that can look like this:
public class product()
{
public decimal Price {get; set;}
public string Description {get; set;}
public string Name {get; set;}
}
In this scenario it is possible that the price comes from database 1, the description form database 2 and the name from database 3. All linked by a unique code.
Question
How would I do this in the hexagonal architecture? Should I:
make 1 productAdapter with multiple repositories (1 for every database)
make an adapter for every database and merge everything in
my domain (which gives my domain code that is related to my
databasestructure)make an adapter for every database and a productAdapter that calls the database adapters?
I hope the description, example and question make sense
c# adapter hexagonal-architecture
add a comment |
up vote
0
down vote
favorite
Description
I'm working with a almost 40 year old project with a lot of legacy code. Over the years multiple databases where added. Now I am converting it step by step to the hexagonal architecture with ports and adapters.
Until now I always created 1 adapter per database. But doing so with this code will give me a representation of my databasestructure in my domain (which I don't want).
Example
If I have a Product object in my domain that can look like this:
public class product()
{
public decimal Price {get; set;}
public string Description {get; set;}
public string Name {get; set;}
}
In this scenario it is possible that the price comes from database 1, the description form database 2 and the name from database 3. All linked by a unique code.
Question
How would I do this in the hexagonal architecture? Should I:
make 1 productAdapter with multiple repositories (1 for every database)
make an adapter for every database and merge everything in
my domain (which gives my domain code that is related to my
databasestructure)make an adapter for every database and a productAdapter that calls the database adapters?
I hope the description, example and question make sense
c# adapter hexagonal-architecture
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Description
I'm working with a almost 40 year old project with a lot of legacy code. Over the years multiple databases where added. Now I am converting it step by step to the hexagonal architecture with ports and adapters.
Until now I always created 1 adapter per database. But doing so with this code will give me a representation of my databasestructure in my domain (which I don't want).
Example
If I have a Product object in my domain that can look like this:
public class product()
{
public decimal Price {get; set;}
public string Description {get; set;}
public string Name {get; set;}
}
In this scenario it is possible that the price comes from database 1, the description form database 2 and the name from database 3. All linked by a unique code.
Question
How would I do this in the hexagonal architecture? Should I:
make 1 productAdapter with multiple repositories (1 for every database)
make an adapter for every database and merge everything in
my domain (which gives my domain code that is related to my
databasestructure)make an adapter for every database and a productAdapter that calls the database adapters?
I hope the description, example and question make sense
c# adapter hexagonal-architecture
Description
I'm working with a almost 40 year old project with a lot of legacy code. Over the years multiple databases where added. Now I am converting it step by step to the hexagonal architecture with ports and adapters.
Until now I always created 1 adapter per database. But doing so with this code will give me a representation of my databasestructure in my domain (which I don't want).
Example
If I have a Product object in my domain that can look like this:
public class product()
{
public decimal Price {get; set;}
public string Description {get; set;}
public string Name {get; set;}
}
In this scenario it is possible that the price comes from database 1, the description form database 2 and the name from database 3. All linked by a unique code.
Question
How would I do this in the hexagonal architecture? Should I:
make 1 productAdapter with multiple repositories (1 for every database)
make an adapter for every database and merge everything in
my domain (which gives my domain code that is related to my
databasestructure)make an adapter for every database and a productAdapter that calls the database adapters?
I hope the description, example and question make sense
c# adapter hexagonal-architecture
c# adapter hexagonal-architecture
asked Nov 12 at 8:03
Marc van Nieuwenhuijzen
1,1771817
1,1771817
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
First of all you should define in your app the port for persisting the product. To do it, you should ask to yourself, from the app point of view:
Does it matter in my app, for solving the problem it is trying to solve, whether the concepts within the product are stored in multiple datastores or just in one?
If it matters, you should define 3 ports (one for each datastore). You would merge the data in your app. Since for your app is important that the concepts are stored in different places, your app knows it, it is part of your app.
If it doesn't matter, you should define just one port to abstract persistence. And define one adapter for the port. The adapter would access the database it needs depending on the property (price, description, name) you are retrieving. I wouldn't abstract the access to these databases in the adapter creating 3 more adapters. I would access the 3 dbs directly from the product adapter. But it's up to you.
It didn’t matter so I went with 1 adapter connecting to 3 databases. Good to get confirmation. Thank you so much
– Marc van Nieuwenhuijzen
Nov 18 at 16:20
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257974%2fload-object-from-multiple-datasources-with-hexagonal-architecture-ports-and-ada%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
First of all you should define in your app the port for persisting the product. To do it, you should ask to yourself, from the app point of view:
Does it matter in my app, for solving the problem it is trying to solve, whether the concepts within the product are stored in multiple datastores or just in one?
If it matters, you should define 3 ports (one for each datastore). You would merge the data in your app. Since for your app is important that the concepts are stored in different places, your app knows it, it is part of your app.
If it doesn't matter, you should define just one port to abstract persistence. And define one adapter for the port. The adapter would access the database it needs depending on the property (price, description, name) you are retrieving. I wouldn't abstract the access to these databases in the adapter creating 3 more adapters. I would access the 3 dbs directly from the product adapter. But it's up to you.
It didn’t matter so I went with 1 adapter connecting to 3 databases. Good to get confirmation. Thank you so much
– Marc van Nieuwenhuijzen
Nov 18 at 16:20
add a comment |
up vote
1
down vote
First of all you should define in your app the port for persisting the product. To do it, you should ask to yourself, from the app point of view:
Does it matter in my app, for solving the problem it is trying to solve, whether the concepts within the product are stored in multiple datastores or just in one?
If it matters, you should define 3 ports (one for each datastore). You would merge the data in your app. Since for your app is important that the concepts are stored in different places, your app knows it, it is part of your app.
If it doesn't matter, you should define just one port to abstract persistence. And define one adapter for the port. The adapter would access the database it needs depending on the property (price, description, name) you are retrieving. I wouldn't abstract the access to these databases in the adapter creating 3 more adapters. I would access the 3 dbs directly from the product adapter. But it's up to you.
It didn’t matter so I went with 1 adapter connecting to 3 databases. Good to get confirmation. Thank you so much
– Marc van Nieuwenhuijzen
Nov 18 at 16:20
add a comment |
up vote
1
down vote
up vote
1
down vote
First of all you should define in your app the port for persisting the product. To do it, you should ask to yourself, from the app point of view:
Does it matter in my app, for solving the problem it is trying to solve, whether the concepts within the product are stored in multiple datastores or just in one?
If it matters, you should define 3 ports (one for each datastore). You would merge the data in your app. Since for your app is important that the concepts are stored in different places, your app knows it, it is part of your app.
If it doesn't matter, you should define just one port to abstract persistence. And define one adapter for the port. The adapter would access the database it needs depending on the property (price, description, name) you are retrieving. I wouldn't abstract the access to these databases in the adapter creating 3 more adapters. I would access the 3 dbs directly from the product adapter. But it's up to you.
First of all you should define in your app the port for persisting the product. To do it, you should ask to yourself, from the app point of view:
Does it matter in my app, for solving the problem it is trying to solve, whether the concepts within the product are stored in multiple datastores or just in one?
If it matters, you should define 3 ports (one for each datastore). You would merge the data in your app. Since for your app is important that the concepts are stored in different places, your app knows it, it is part of your app.
If it doesn't matter, you should define just one port to abstract persistence. And define one adapter for the port. The adapter would access the database it needs depending on the property (price, description, name) you are retrieving. I wouldn't abstract the access to these databases in the adapter creating 3 more adapters. I would access the 3 dbs directly from the product adapter. But it's up to you.
answered Nov 18 at 9:42
choquero70
1,05611530
1,05611530
It didn’t matter so I went with 1 adapter connecting to 3 databases. Good to get confirmation. Thank you so much
– Marc van Nieuwenhuijzen
Nov 18 at 16:20
add a comment |
It didn’t matter so I went with 1 adapter connecting to 3 databases. Good to get confirmation. Thank you so much
– Marc van Nieuwenhuijzen
Nov 18 at 16:20
It didn’t matter so I went with 1 adapter connecting to 3 databases. Good to get confirmation. Thank you so much
– Marc van Nieuwenhuijzen
Nov 18 at 16:20
It didn’t matter so I went with 1 adapter connecting to 3 databases. Good to get confirmation. Thank you so much
– Marc van Nieuwenhuijzen
Nov 18 at 16:20
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257974%2fload-object-from-multiple-datasources-with-hexagonal-architecture-ports-and-ada%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown