Can DDD entity rely upon infrastructure library?DDD: Creating reusable modules and service type distinctions (Domain, Infrastructure, Application)DDD, where to use infrastructure servicesConfiguring entity behavior DDDDomain Driven Design in Net - Project StructureDDD Injecting Services on Entity Methods CallsIs it acceptable for a Domain Entity to implement an interface?How to generate a Natural key for a Domain entity?Separation of application logic and domain logic in Clean ArchitectureVoid Or Other Result In DDD OperationAren't Domain Driven Design/“hexagonal architecture” with real world constraints and the insistence on “non anemic model” contradictory?

What is game ban VS VAC ban in steam?

Why do Russians call their women expensive ("дорогая")?

What are the benefits of cryosleep?

Do creatures all have the same statistics upon being reanimated via the Animate Dead spell?

etoolbox: AtBeginEnvironment is not At Begin Environment

How can a single Member of the House block a Congressional bill?

Beginner's snake game using PyGame

Can a non-EU citizen travel within the Schengen area without identity documents?

If a problem only occurs randomly once in every N times on average, how many tests do I have to perform to be certain that it's now fixed?

Intuition behind eigenvalues of an adjacency matrix

Differences between “pas vrai ?”, “c’est ça ?”, “hein ?”, and “n’est-ce pas ?”

Self-Preservation: How to DM NPCs that Love Living?

Get LaTeX form from step by step solution

Smart people send dumb people to a new planet on a space craft that crashes into a body of water

What was this black-and-white film set in the Arctic or Antarctic where the monster/alien gets fried in the end?

Modern approach to radio buttons

Geometry affects line breaking

The term for the person/group a political party aligns themselves with to appear concerned about the general public

Will My Circuit Work As intended?

What are the slash markings on Gatwick's 08R/26L?

Why is there a need to modify system call tables in linux?

Is there an evolutionary advantage to having two heads?

Can a wire having a 610-670 THz (frequency of blue light) AC frequency supply, generate blue light?

Is there a rule that prohibits us from using 2 possessives in a row?



Can DDD entity rely upon infrastructure library?


DDD: Creating reusable modules and service type distinctions (Domain, Infrastructure, Application)DDD, where to use infrastructure servicesConfiguring entity behavior DDDDomain Driven Design in Net - Project StructureDDD Injecting Services on Entity Methods CallsIs it acceptable for a Domain Entity to implement an interface?How to generate a Natural key for a Domain entity?Separation of application logic and domain logic in Clean ArchitectureVoid Or Other Result In DDD OperationAren't Domain Driven Design/“hexagonal architecture” with real world constraints and the insistence on “non anemic model” contradictory?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















Suppose I want this on my User entity:



user.createNewSecurityToken();


That means:



public void createNewSecurityToken() 
var buffer = new byte[32];
new RNGCryptoServiceProvider().GetBytes(buffer); // <--- here's the issue
this.Token = Convert.ToBase64String(buffer);



This is not a DI dependency, just a class from the infrastructure. But does that "break" DDD?



The alternative is this:



user.setSecurityToken(token); // pass it in (probably from a domain service)


But that leads to anemic entities.



Which is the preferred DDD approach, and what considerations should I take into account when faced with this sort of design decision?



UPDATE



Based on comments below, this leads to a more general question: what can I / can't I use in an entity? Domain services, application services, infrastructure services, framework classes, etc. - I know I can't inject DI-based services, or use infrastructure services, but what about the rest? What should I not use inside an entity?










share|improve this question









New contributor



lonix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • RNGCryptoServiceProvider just looks like an implementation detail. I don't think it is of any interest for the DDD view of the design.

    – Lutz Horn
    May 23 at 8:29











  • @LutzHorn So I understand you correctly, you mean it's "okay" to use it in a DDD entity?

    – lonix
    May 23 at 8:47











  • @LutzHorn Also that raises the question what is the dividing line between items that are okay to use and those that aren't?

    – lonix
    May 23 at 8:49






  • 1





    Yes. The domain entity would be User. How the internal behaviour of this entity is implemented should not matter.

    – Lutz Horn
    May 23 at 8:49











  • @LutzHorn That makes sense now, thanks. But... why not use domain/application/infrastructure services inside an entity - I could use the same argument that it's an internal behavior?

    – lonix
    May 23 at 8:58

















2















Suppose I want this on my User entity:



user.createNewSecurityToken();


That means:



public void createNewSecurityToken() 
var buffer = new byte[32];
new RNGCryptoServiceProvider().GetBytes(buffer); // <--- here's the issue
this.Token = Convert.ToBase64String(buffer);



This is not a DI dependency, just a class from the infrastructure. But does that "break" DDD?



The alternative is this:



user.setSecurityToken(token); // pass it in (probably from a domain service)


But that leads to anemic entities.



Which is the preferred DDD approach, and what considerations should I take into account when faced with this sort of design decision?



UPDATE



Based on comments below, this leads to a more general question: what can I / can't I use in an entity? Domain services, application services, infrastructure services, framework classes, etc. - I know I can't inject DI-based services, or use infrastructure services, but what about the rest? What should I not use inside an entity?










share|improve this question









New contributor



lonix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • RNGCryptoServiceProvider just looks like an implementation detail. I don't think it is of any interest for the DDD view of the design.

    – Lutz Horn
    May 23 at 8:29











  • @LutzHorn So I understand you correctly, you mean it's "okay" to use it in a DDD entity?

    – lonix
    May 23 at 8:47











  • @LutzHorn Also that raises the question what is the dividing line between items that are okay to use and those that aren't?

    – lonix
    May 23 at 8:49






  • 1





    Yes. The domain entity would be User. How the internal behaviour of this entity is implemented should not matter.

    – Lutz Horn
    May 23 at 8:49











  • @LutzHorn That makes sense now, thanks. But... why not use domain/application/infrastructure services inside an entity - I could use the same argument that it's an internal behavior?

    – lonix
    May 23 at 8:58













2












2








2


0






Suppose I want this on my User entity:



user.createNewSecurityToken();


That means:



public void createNewSecurityToken() 
var buffer = new byte[32];
new RNGCryptoServiceProvider().GetBytes(buffer); // <--- here's the issue
this.Token = Convert.ToBase64String(buffer);



This is not a DI dependency, just a class from the infrastructure. But does that "break" DDD?



The alternative is this:



user.setSecurityToken(token); // pass it in (probably from a domain service)


But that leads to anemic entities.



Which is the preferred DDD approach, and what considerations should I take into account when faced with this sort of design decision?



UPDATE



Based on comments below, this leads to a more general question: what can I / can't I use in an entity? Domain services, application services, infrastructure services, framework classes, etc. - I know I can't inject DI-based services, or use infrastructure services, but what about the rest? What should I not use inside an entity?










share|improve this question









New contributor



lonix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Suppose I want this on my User entity:



user.createNewSecurityToken();


That means:



public void createNewSecurityToken() 
var buffer = new byte[32];
new RNGCryptoServiceProvider().GetBytes(buffer); // <--- here's the issue
this.Token = Convert.ToBase64String(buffer);



This is not a DI dependency, just a class from the infrastructure. But does that "break" DDD?



The alternative is this:



user.setSecurityToken(token); // pass it in (probably from a domain service)


But that leads to anemic entities.



Which is the preferred DDD approach, and what considerations should I take into account when faced with this sort of design decision?



UPDATE



Based on comments below, this leads to a more general question: what can I / can't I use in an entity? Domain services, application services, infrastructure services, framework classes, etc. - I know I can't inject DI-based services, or use infrastructure services, but what about the rest? What should I not use inside an entity?







domain-driven-design






share|improve this question









New contributor



lonix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share|improve this question









New contributor



lonix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share|improve this question




share|improve this question








edited May 23 at 9:18







lonix













New contributor



lonix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








asked May 23 at 7:21









lonixlonix

1214




1214




New contributor



lonix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




New contributor




lonix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.














  • RNGCryptoServiceProvider just looks like an implementation detail. I don't think it is of any interest for the DDD view of the design.

    – Lutz Horn
    May 23 at 8:29











  • @LutzHorn So I understand you correctly, you mean it's "okay" to use it in a DDD entity?

    – lonix
    May 23 at 8:47











  • @LutzHorn Also that raises the question what is the dividing line between items that are okay to use and those that aren't?

    – lonix
    May 23 at 8:49






  • 1





    Yes. The domain entity would be User. How the internal behaviour of this entity is implemented should not matter.

    – Lutz Horn
    May 23 at 8:49











  • @LutzHorn That makes sense now, thanks. But... why not use domain/application/infrastructure services inside an entity - I could use the same argument that it's an internal behavior?

    – lonix
    May 23 at 8:58

















  • RNGCryptoServiceProvider just looks like an implementation detail. I don't think it is of any interest for the DDD view of the design.

    – Lutz Horn
    May 23 at 8:29











  • @LutzHorn So I understand you correctly, you mean it's "okay" to use it in a DDD entity?

    – lonix
    May 23 at 8:47











  • @LutzHorn Also that raises the question what is the dividing line between items that are okay to use and those that aren't?

    – lonix
    May 23 at 8:49






  • 1





    Yes. The domain entity would be User. How the internal behaviour of this entity is implemented should not matter.

    – Lutz Horn
    May 23 at 8:49











  • @LutzHorn That makes sense now, thanks. But... why not use domain/application/infrastructure services inside an entity - I could use the same argument that it's an internal behavior?

    – lonix
    May 23 at 8:58
















RNGCryptoServiceProvider just looks like an implementation detail. I don't think it is of any interest for the DDD view of the design.

– Lutz Horn
May 23 at 8:29





RNGCryptoServiceProvider just looks like an implementation detail. I don't think it is of any interest for the DDD view of the design.

– Lutz Horn
May 23 at 8:29













@LutzHorn So I understand you correctly, you mean it's "okay" to use it in a DDD entity?

– lonix
May 23 at 8:47





@LutzHorn So I understand you correctly, you mean it's "okay" to use it in a DDD entity?

– lonix
May 23 at 8:47













@LutzHorn Also that raises the question what is the dividing line between items that are okay to use and those that aren't?

– lonix
May 23 at 8:49





@LutzHorn Also that raises the question what is the dividing line between items that are okay to use and those that aren't?

– lonix
May 23 at 8:49




1




1





Yes. The domain entity would be User. How the internal behaviour of this entity is implemented should not matter.

– Lutz Horn
May 23 at 8:49





Yes. The domain entity would be User. How the internal behaviour of this entity is implemented should not matter.

– Lutz Horn
May 23 at 8:49













@LutzHorn That makes sense now, thanks. But... why not use domain/application/infrastructure services inside an entity - I could use the same argument that it's an internal behavior?

– lonix
May 23 at 8:58





@LutzHorn That makes sense now, thanks. But... why not use domain/application/infrastructure services inside an entity - I could use the same argument that it's an internal behavior?

– lonix
May 23 at 8:58










2 Answers
2






active

oldest

votes


















3














Think of it this way, which one represents something meaningful in your domain? Something that somebody familiar with the domain (but not necessarily the technology) would understand. I.e. which one is more likely to be part of the Ubiquitous Language?



Option #1: setSecurityToken()? Seems technical, it's a setter.



Option #2: createNewSecurityToken()? Seems better, similar words may be in your requirements somewhere? Still it is a bit technical, but might be ok for your domain.



In general what you "can or can not do in an Entity" depends on who you ask. Some people prefer purely anemic entities containing "pure" data with services containing all the logic. Others, me included, prefer a model based on behavior strongly mirroring the Ubiquitous Language, with no anemic objects (i.e. data) nor services (i.e. procedures).



To be honest, most of the examples on the 'net and books (Vaughn Vernon et al.) prefer the anemic object/service (i.e. data/procedure) approach, with some minimal behavior sometimes sprinkled in that can not require any dependencies. This is probably what would be most familiar to other people.



If you want to avoid anemic entities, i.e. embrace object-orientation, you will have to think for yourself, as there is very little about it online. Here is a presentation of mine on the topic.






share|improve this answer

























  • So you are saying that it's okay to use the infrastructure's crypto library inside the entity, in order to have option 2? Okay, that makes my life simpler! :-) But then, what do you believe I can/can't use inside an entity - where do I draw the line?

    – lonix
    May 23 at 9:37












  • Yes, entities can use whatever they need for their logic. Basic design practices apply however. If it gets more than a couple of lines, I would extract that code to a new object (perhaps a value object) SecurityToken, etc. As with other objects it should be kept rather small and focused, but it can use any collaborator object it needs.

    – Robert Bräutigam
    May 23 at 9:44











  • "...but it can use any collaborator object it needs" and I assume that of course we mean something "light" (e.g. new Foo().doSomething()), not a service dependency that must go in via DI.

    – lonix
    May 23 at 10:38












  • I do mean anything. However, if you model the business consistently and avoid anemic things, I doubt there will be any "Services" left to write. It will be just another object coming through the constructor like everything else.

    – Robert Bräutigam
    May 23 at 11:45


















3














With a DDD approach you are trying to match your Entities with the 'Domain Language'.



I find it hard to believe that the business says "A User creates a new security token". If they do then sure, the User object should have that method and the required logic for doing the job.



But I think it would be more usual for the Business to say "The User logs in" and for the devs to say "The Auth service creates a token for users".



So now you have User.LogIn() and AuthService.GenerateToken() If they are in the same Domain then you can have one reference the other, but that seems unlikely. in which case the AuthService is a Domain Service.



Which you could either inject into user or User's Aggregate Root to enable the LogIn() method.



Or, you could re think the Domain language and say 'does a user log in? or does the AuthService authenticate the User? allowing you to remove the LogIn() method from user and follow what is now a pretty standard approach of moving all the Auth concerns out of the Domain.






share|improve this answer























  • Thanks, I didn't consider that!

    – lonix
    May 23 at 10:23











  • I disagree with this approach for two reasons. First, AuthService is not a domain thing (usually). If I write my banking app, none of my business counterparts would know what "AuthService" is and why it's there. It's a technical thing. Second, User.createNewSecurityToken() does not imply that the User in real-life should create the security token. Objects in general do not mirror real-life. They are a model of the business concepts and behavior, a slight but crucial difference.

    – Robert Bräutigam
    May 23 at 10:23












  • But I do agree, that the behavior we are trying to model here is probably login() or something similar, and not createNewSecurityToken().

    – Robert Bräutigam
    May 23 at 10:25












Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "131"
;
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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
);



);






lonix is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsoftwareengineering.stackexchange.com%2fquestions%2f392290%2fcan-ddd-entity-rely-upon-infrastructure-library%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














Think of it this way, which one represents something meaningful in your domain? Something that somebody familiar with the domain (but not necessarily the technology) would understand. I.e. which one is more likely to be part of the Ubiquitous Language?



Option #1: setSecurityToken()? Seems technical, it's a setter.



Option #2: createNewSecurityToken()? Seems better, similar words may be in your requirements somewhere? Still it is a bit technical, but might be ok for your domain.



In general what you "can or can not do in an Entity" depends on who you ask. Some people prefer purely anemic entities containing "pure" data with services containing all the logic. Others, me included, prefer a model based on behavior strongly mirroring the Ubiquitous Language, with no anemic objects (i.e. data) nor services (i.e. procedures).



To be honest, most of the examples on the 'net and books (Vaughn Vernon et al.) prefer the anemic object/service (i.e. data/procedure) approach, with some minimal behavior sometimes sprinkled in that can not require any dependencies. This is probably what would be most familiar to other people.



If you want to avoid anemic entities, i.e. embrace object-orientation, you will have to think for yourself, as there is very little about it online. Here is a presentation of mine on the topic.






share|improve this answer

























  • So you are saying that it's okay to use the infrastructure's crypto library inside the entity, in order to have option 2? Okay, that makes my life simpler! :-) But then, what do you believe I can/can't use inside an entity - where do I draw the line?

    – lonix
    May 23 at 9:37












  • Yes, entities can use whatever they need for their logic. Basic design practices apply however. If it gets more than a couple of lines, I would extract that code to a new object (perhaps a value object) SecurityToken, etc. As with other objects it should be kept rather small and focused, but it can use any collaborator object it needs.

    – Robert Bräutigam
    May 23 at 9:44











  • "...but it can use any collaborator object it needs" and I assume that of course we mean something "light" (e.g. new Foo().doSomething()), not a service dependency that must go in via DI.

    – lonix
    May 23 at 10:38












  • I do mean anything. However, if you model the business consistently and avoid anemic things, I doubt there will be any "Services" left to write. It will be just another object coming through the constructor like everything else.

    – Robert Bräutigam
    May 23 at 11:45















3














Think of it this way, which one represents something meaningful in your domain? Something that somebody familiar with the domain (but not necessarily the technology) would understand. I.e. which one is more likely to be part of the Ubiquitous Language?



Option #1: setSecurityToken()? Seems technical, it's a setter.



Option #2: createNewSecurityToken()? Seems better, similar words may be in your requirements somewhere? Still it is a bit technical, but might be ok for your domain.



In general what you "can or can not do in an Entity" depends on who you ask. Some people prefer purely anemic entities containing "pure" data with services containing all the logic. Others, me included, prefer a model based on behavior strongly mirroring the Ubiquitous Language, with no anemic objects (i.e. data) nor services (i.e. procedures).



To be honest, most of the examples on the 'net and books (Vaughn Vernon et al.) prefer the anemic object/service (i.e. data/procedure) approach, with some minimal behavior sometimes sprinkled in that can not require any dependencies. This is probably what would be most familiar to other people.



If you want to avoid anemic entities, i.e. embrace object-orientation, you will have to think for yourself, as there is very little about it online. Here is a presentation of mine on the topic.






share|improve this answer

























  • So you are saying that it's okay to use the infrastructure's crypto library inside the entity, in order to have option 2? Okay, that makes my life simpler! :-) But then, what do you believe I can/can't use inside an entity - where do I draw the line?

    – lonix
    May 23 at 9:37












  • Yes, entities can use whatever they need for their logic. Basic design practices apply however. If it gets more than a couple of lines, I would extract that code to a new object (perhaps a value object) SecurityToken, etc. As with other objects it should be kept rather small and focused, but it can use any collaborator object it needs.

    – Robert Bräutigam
    May 23 at 9:44











  • "...but it can use any collaborator object it needs" and I assume that of course we mean something "light" (e.g. new Foo().doSomething()), not a service dependency that must go in via DI.

    – lonix
    May 23 at 10:38












  • I do mean anything. However, if you model the business consistently and avoid anemic things, I doubt there will be any "Services" left to write. It will be just another object coming through the constructor like everything else.

    – Robert Bräutigam
    May 23 at 11:45













3












3








3







Think of it this way, which one represents something meaningful in your domain? Something that somebody familiar with the domain (but not necessarily the technology) would understand. I.e. which one is more likely to be part of the Ubiquitous Language?



Option #1: setSecurityToken()? Seems technical, it's a setter.



Option #2: createNewSecurityToken()? Seems better, similar words may be in your requirements somewhere? Still it is a bit technical, but might be ok for your domain.



In general what you "can or can not do in an Entity" depends on who you ask. Some people prefer purely anemic entities containing "pure" data with services containing all the logic. Others, me included, prefer a model based on behavior strongly mirroring the Ubiquitous Language, with no anemic objects (i.e. data) nor services (i.e. procedures).



To be honest, most of the examples on the 'net and books (Vaughn Vernon et al.) prefer the anemic object/service (i.e. data/procedure) approach, with some minimal behavior sometimes sprinkled in that can not require any dependencies. This is probably what would be most familiar to other people.



If you want to avoid anemic entities, i.e. embrace object-orientation, you will have to think for yourself, as there is very little about it online. Here is a presentation of mine on the topic.






share|improve this answer















Think of it this way, which one represents something meaningful in your domain? Something that somebody familiar with the domain (but not necessarily the technology) would understand. I.e. which one is more likely to be part of the Ubiquitous Language?



Option #1: setSecurityToken()? Seems technical, it's a setter.



Option #2: createNewSecurityToken()? Seems better, similar words may be in your requirements somewhere? Still it is a bit technical, but might be ok for your domain.



In general what you "can or can not do in an Entity" depends on who you ask. Some people prefer purely anemic entities containing "pure" data with services containing all the logic. Others, me included, prefer a model based on behavior strongly mirroring the Ubiquitous Language, with no anemic objects (i.e. data) nor services (i.e. procedures).



To be honest, most of the examples on the 'net and books (Vaughn Vernon et al.) prefer the anemic object/service (i.e. data/procedure) approach, with some minimal behavior sometimes sprinkled in that can not require any dependencies. This is probably what would be most familiar to other people.



If you want to avoid anemic entities, i.e. embrace object-orientation, you will have to think for yourself, as there is very little about it online. Here is a presentation of mine on the topic.







share|improve this answer














share|improve this answer



share|improve this answer








edited May 23 at 9:37

























answered May 23 at 9:30









Robert BräutigamRobert Bräutigam

2,602715




2,602715












  • So you are saying that it's okay to use the infrastructure's crypto library inside the entity, in order to have option 2? Okay, that makes my life simpler! :-) But then, what do you believe I can/can't use inside an entity - where do I draw the line?

    – lonix
    May 23 at 9:37












  • Yes, entities can use whatever they need for their logic. Basic design practices apply however. If it gets more than a couple of lines, I would extract that code to a new object (perhaps a value object) SecurityToken, etc. As with other objects it should be kept rather small and focused, but it can use any collaborator object it needs.

    – Robert Bräutigam
    May 23 at 9:44











  • "...but it can use any collaborator object it needs" and I assume that of course we mean something "light" (e.g. new Foo().doSomething()), not a service dependency that must go in via DI.

    – lonix
    May 23 at 10:38












  • I do mean anything. However, if you model the business consistently and avoid anemic things, I doubt there will be any "Services" left to write. It will be just another object coming through the constructor like everything else.

    – Robert Bräutigam
    May 23 at 11:45

















  • So you are saying that it's okay to use the infrastructure's crypto library inside the entity, in order to have option 2? Okay, that makes my life simpler! :-) But then, what do you believe I can/can't use inside an entity - where do I draw the line?

    – lonix
    May 23 at 9:37












  • Yes, entities can use whatever they need for their logic. Basic design practices apply however. If it gets more than a couple of lines, I would extract that code to a new object (perhaps a value object) SecurityToken, etc. As with other objects it should be kept rather small and focused, but it can use any collaborator object it needs.

    – Robert Bräutigam
    May 23 at 9:44











  • "...but it can use any collaborator object it needs" and I assume that of course we mean something "light" (e.g. new Foo().doSomething()), not a service dependency that must go in via DI.

    – lonix
    May 23 at 10:38












  • I do mean anything. However, if you model the business consistently and avoid anemic things, I doubt there will be any "Services" left to write. It will be just another object coming through the constructor like everything else.

    – Robert Bräutigam
    May 23 at 11:45
















So you are saying that it's okay to use the infrastructure's crypto library inside the entity, in order to have option 2? Okay, that makes my life simpler! :-) But then, what do you believe I can/can't use inside an entity - where do I draw the line?

– lonix
May 23 at 9:37






So you are saying that it's okay to use the infrastructure's crypto library inside the entity, in order to have option 2? Okay, that makes my life simpler! :-) But then, what do you believe I can/can't use inside an entity - where do I draw the line?

– lonix
May 23 at 9:37














Yes, entities can use whatever they need for their logic. Basic design practices apply however. If it gets more than a couple of lines, I would extract that code to a new object (perhaps a value object) SecurityToken, etc. As with other objects it should be kept rather small and focused, but it can use any collaborator object it needs.

– Robert Bräutigam
May 23 at 9:44





Yes, entities can use whatever they need for their logic. Basic design practices apply however. If it gets more than a couple of lines, I would extract that code to a new object (perhaps a value object) SecurityToken, etc. As with other objects it should be kept rather small and focused, but it can use any collaborator object it needs.

– Robert Bräutigam
May 23 at 9:44













"...but it can use any collaborator object it needs" and I assume that of course we mean something "light" (e.g. new Foo().doSomething()), not a service dependency that must go in via DI.

– lonix
May 23 at 10:38






"...but it can use any collaborator object it needs" and I assume that of course we mean something "light" (e.g. new Foo().doSomething()), not a service dependency that must go in via DI.

– lonix
May 23 at 10:38














I do mean anything. However, if you model the business consistently and avoid anemic things, I doubt there will be any "Services" left to write. It will be just another object coming through the constructor like everything else.

– Robert Bräutigam
May 23 at 11:45





I do mean anything. However, if you model the business consistently and avoid anemic things, I doubt there will be any "Services" left to write. It will be just another object coming through the constructor like everything else.

– Robert Bräutigam
May 23 at 11:45













3














With a DDD approach you are trying to match your Entities with the 'Domain Language'.



I find it hard to believe that the business says "A User creates a new security token". If they do then sure, the User object should have that method and the required logic for doing the job.



But I think it would be more usual for the Business to say "The User logs in" and for the devs to say "The Auth service creates a token for users".



So now you have User.LogIn() and AuthService.GenerateToken() If they are in the same Domain then you can have one reference the other, but that seems unlikely. in which case the AuthService is a Domain Service.



Which you could either inject into user or User's Aggregate Root to enable the LogIn() method.



Or, you could re think the Domain language and say 'does a user log in? or does the AuthService authenticate the User? allowing you to remove the LogIn() method from user and follow what is now a pretty standard approach of moving all the Auth concerns out of the Domain.






share|improve this answer























  • Thanks, I didn't consider that!

    – lonix
    May 23 at 10:23











  • I disagree with this approach for two reasons. First, AuthService is not a domain thing (usually). If I write my banking app, none of my business counterparts would know what "AuthService" is and why it's there. It's a technical thing. Second, User.createNewSecurityToken() does not imply that the User in real-life should create the security token. Objects in general do not mirror real-life. They are a model of the business concepts and behavior, a slight but crucial difference.

    – Robert Bräutigam
    May 23 at 10:23












  • But I do agree, that the behavior we are trying to model here is probably login() or something similar, and not createNewSecurityToken().

    – Robert Bräutigam
    May 23 at 10:25
















3














With a DDD approach you are trying to match your Entities with the 'Domain Language'.



I find it hard to believe that the business says "A User creates a new security token". If they do then sure, the User object should have that method and the required logic for doing the job.



But I think it would be more usual for the Business to say "The User logs in" and for the devs to say "The Auth service creates a token for users".



So now you have User.LogIn() and AuthService.GenerateToken() If they are in the same Domain then you can have one reference the other, but that seems unlikely. in which case the AuthService is a Domain Service.



Which you could either inject into user or User's Aggregate Root to enable the LogIn() method.



Or, you could re think the Domain language and say 'does a user log in? or does the AuthService authenticate the User? allowing you to remove the LogIn() method from user and follow what is now a pretty standard approach of moving all the Auth concerns out of the Domain.






share|improve this answer























  • Thanks, I didn't consider that!

    – lonix
    May 23 at 10:23











  • I disagree with this approach for two reasons. First, AuthService is not a domain thing (usually). If I write my banking app, none of my business counterparts would know what "AuthService" is and why it's there. It's a technical thing. Second, User.createNewSecurityToken() does not imply that the User in real-life should create the security token. Objects in general do not mirror real-life. They are a model of the business concepts and behavior, a slight but crucial difference.

    – Robert Bräutigam
    May 23 at 10:23












  • But I do agree, that the behavior we are trying to model here is probably login() or something similar, and not createNewSecurityToken().

    – Robert Bräutigam
    May 23 at 10:25














3












3








3







With a DDD approach you are trying to match your Entities with the 'Domain Language'.



I find it hard to believe that the business says "A User creates a new security token". If they do then sure, the User object should have that method and the required logic for doing the job.



But I think it would be more usual for the Business to say "The User logs in" and for the devs to say "The Auth service creates a token for users".



So now you have User.LogIn() and AuthService.GenerateToken() If they are in the same Domain then you can have one reference the other, but that seems unlikely. in which case the AuthService is a Domain Service.



Which you could either inject into user or User's Aggregate Root to enable the LogIn() method.



Or, you could re think the Domain language and say 'does a user log in? or does the AuthService authenticate the User? allowing you to remove the LogIn() method from user and follow what is now a pretty standard approach of moving all the Auth concerns out of the Domain.






share|improve this answer













With a DDD approach you are trying to match your Entities with the 'Domain Language'.



I find it hard to believe that the business says "A User creates a new security token". If they do then sure, the User object should have that method and the required logic for doing the job.



But I think it would be more usual for the Business to say "The User logs in" and for the devs to say "The Auth service creates a token for users".



So now you have User.LogIn() and AuthService.GenerateToken() If they are in the same Domain then you can have one reference the other, but that seems unlikely. in which case the AuthService is a Domain Service.



Which you could either inject into user or User's Aggregate Root to enable the LogIn() method.



Or, you could re think the Domain language and say 'does a user log in? or does the AuthService authenticate the User? allowing you to remove the LogIn() method from user and follow what is now a pretty standard approach of moving all the Auth concerns out of the Domain.







share|improve this answer












share|improve this answer



share|improve this answer










answered May 23 at 10:00









EwanEwan

45k338101




45k338101












  • Thanks, I didn't consider that!

    – lonix
    May 23 at 10:23











  • I disagree with this approach for two reasons. First, AuthService is not a domain thing (usually). If I write my banking app, none of my business counterparts would know what "AuthService" is and why it's there. It's a technical thing. Second, User.createNewSecurityToken() does not imply that the User in real-life should create the security token. Objects in general do not mirror real-life. They are a model of the business concepts and behavior, a slight but crucial difference.

    – Robert Bräutigam
    May 23 at 10:23












  • But I do agree, that the behavior we are trying to model here is probably login() or something similar, and not createNewSecurityToken().

    – Robert Bräutigam
    May 23 at 10:25


















  • Thanks, I didn't consider that!

    – lonix
    May 23 at 10:23











  • I disagree with this approach for two reasons. First, AuthService is not a domain thing (usually). If I write my banking app, none of my business counterparts would know what "AuthService" is and why it's there. It's a technical thing. Second, User.createNewSecurityToken() does not imply that the User in real-life should create the security token. Objects in general do not mirror real-life. They are a model of the business concepts and behavior, a slight but crucial difference.

    – Robert Bräutigam
    May 23 at 10:23












  • But I do agree, that the behavior we are trying to model here is probably login() or something similar, and not createNewSecurityToken().

    – Robert Bräutigam
    May 23 at 10:25

















Thanks, I didn't consider that!

– lonix
May 23 at 10:23





Thanks, I didn't consider that!

– lonix
May 23 at 10:23













I disagree with this approach for two reasons. First, AuthService is not a domain thing (usually). If I write my banking app, none of my business counterparts would know what "AuthService" is and why it's there. It's a technical thing. Second, User.createNewSecurityToken() does not imply that the User in real-life should create the security token. Objects in general do not mirror real-life. They are a model of the business concepts and behavior, a slight but crucial difference.

– Robert Bräutigam
May 23 at 10:23






I disagree with this approach for two reasons. First, AuthService is not a domain thing (usually). If I write my banking app, none of my business counterparts would know what "AuthService" is and why it's there. It's a technical thing. Second, User.createNewSecurityToken() does not imply that the User in real-life should create the security token. Objects in general do not mirror real-life. They are a model of the business concepts and behavior, a slight but crucial difference.

– Robert Bräutigam
May 23 at 10:23














But I do agree, that the behavior we are trying to model here is probably login() or something similar, and not createNewSecurityToken().

– Robert Bräutigam
May 23 at 10:25






But I do agree, that the behavior we are trying to model here is probably login() or something similar, and not createNewSecurityToken().

– Robert Bräutigam
May 23 at 10:25











lonix is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















lonix is a new contributor. Be nice, and check out our Code of Conduct.












lonix is a new contributor. Be nice, and check out our Code of Conduct.











lonix is a new contributor. Be nice, and check out our Code of Conduct.














Thanks for contributing an answer to Software Engineering Stack Exchange!


  • 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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsoftwareengineering.stackexchange.com%2fquestions%2f392290%2fcan-ddd-entity-rely-upon-infrastructure-library%23new-answer', 'question_page');

);

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







Popular posts from this blog

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?