tag:blogger.com,1999:blog-8336318365940619669.post5299659691868892677..comments2024-03-01T16:50:39.029+01:00Comments on Horsdal Consult: Options for DCI on .NETChristian Horsdalhttp://www.blogger.com/profile/07782376855026802670noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-8336318365940619669.post-8280145173914903382013-03-06T09:38:25.781+01:002013-03-06T09:38:25.781+01:00This is my implementation of the DCI in C# using t...This is my implementation of the DCI in C# using the decorator pattern. What do you guys think.<br /><br />http://pastie.org/6403027Orsonhttps://www.blogger.com/profile/13498091263286678249noreply@blogger.comtag:blogger.com,1999:blog-8336318365940619669.post-60633459588925131682011-05-31T20:44:13.852+02:002011-05-31T20:44:13.852+02:00@jordao: Thanks for the pointer. You may find http...@jordao: Thanks for the pointer. You may find http://remix.codeplex.com/ which a .NET mixin implementation, that I guess could also be used for doing DCI.Christian Horsdalhttps://www.blogger.com/profile/07782376855026802670noreply@blogger.comtag:blogger.com,1999:blog-8336318365940619669.post-43104808873172460212011-05-31T19:06:02.092+02:002011-05-31T19:06:02.092+02:00For an option very low in "mainstreamness&quo...For an option very low in "mainstreamness", you can take a look at NRoles, a post-compiler I created to enable roles in C#:<br /><br />http://codecrafter.blogspot.com/2011/05/nroles-experiment-with-roles-in-c.htmlJordãohttps://www.blogger.com/profile/07178574753933019008noreply@blogger.comtag:blogger.com,1999:blog-8336318365940619669.post-62072203468528764252011-01-07T09:06:50.596+01:002011-01-07T09:06:50.596+01:00That's an interesting approach. What is the ra...That's an interesting approach. What is the rationale behind the design? <br />To be honest it feels a bit convoluted to me. E.g. the indirection level in calling the role code seem somewhat complicated; basically the role code is assigned to objects and then executed immediately, so why not a more direct approach?<br />And is it enough to have just one method with the action signature on the role? -In the general case I dont think it is.Christian Horsdalhttps://www.blogger.com/profile/07782376855026802670noreply@blogger.comtag:blogger.com,1999:blog-8336318365940619669.post-71558545308609155362011-01-07T03:36:20.830+01:002011-01-07T03:36:20.830+01:00ok i think this one much more easier
http://www.p...ok i think this one much more easier<br /><br />http://www.pastie.org/1436040ryzamhttps://www.blogger.com/profile/08948488698923418322noreply@blogger.comtag:blogger.com,1999:blog-8336318365940619669.post-70819269012009601432011-01-06T08:46:35.161+01:002011-01-06T08:46:35.161+01:00@ryzam:
I might be misunderstanding you, but the r...@ryzam:<br />I might be misunderstanding you, but the role is to be assigned to an entity, not a value object, because the entities are the objects that appear as actors in the use cases. The value object are just values.Christian Horsdalhttps://www.blogger.com/profile/07782376855026802670noreply@blogger.comtag:blogger.com,1999:blog-8336318365940619669.post-33018100520771934982011-01-06T03:25:17.340+01:002011-01-06T03:25:17.340+01:00but what if the concrete type is a value object wh...but what if the concrete type is a value object where you can use anywhere in your entity?ryzamhttps://www.blogger.com/profile/08948488698923418322noreply@blogger.comtag:blogger.com,1999:blog-8336318365940619669.post-47810330072644965242011-01-05T15:10:49.783+01:002011-01-05T15:10:49.783+01:00@ryzam:
Well, I see a couple of issues:
Firstly, ...@ryzam:<br />Well, I see a couple of issues: <br />Firstly, the role is implemented as extension methods on the account type, which is a concrete type, thus the the role only be applied to that single domain type (and its inheritors). You want to be able to have a full many-to-many relationship between roles and domain types.<br />Seondly, the I dont really see the point of using a dynamic field for the role implementation. Could you maybe, explain this choice?Christian Horsdalhttps://www.blogger.com/profile/07782376855026802670noreply@blogger.comtag:blogger.com,1999:blog-8336318365940619669.post-40941752906357352622011-01-05T07:35:13.058+01:002011-01-05T07:35:13.058+01:00Hi,
what do you think about this?
public class A...Hi,<br /><br />what do you think about this?<br /><br />public class Account<br /> {<br /> public dynamic Role { get; set; }<br /><br /> public decimal Balance { get; set; }<br /><br /> public void IncreaseBalance(decimal amount)<br /> {<br /> this.Balance += amount;<br /> }<br /><br /> public void DecreaseBalance(decimal amount)<br /> {<br /> this.Balance -= amount;<br /> }<br /><br /> }<br /><br /> public static class MoneySourceRole<br /> {<br /> public static void TransferTo(this Account source,Account sink, decimal amount)<br /> {<br /> source.Role = (Action)(() =><br /> {<br /> source.IncreaseBalance(amount);<br /> sink.DecreaseBalance(amount);<br /> }<br /> );<br /><br /> Action action = (Action)source.Role;<br /> action();<br /> }<br /> }<br /><br /> public class AppConsole<br /> {<br /> public static void Main(string[] args)<br /> {<br /> var account1 = new Account { Balance = 10m };<br /> var account2 = new Account { Balance = 30m };<br /><br /> account2.TransferTo(account1, 5m);<br /><br /> Console.WriteLine(account1.Balance);<br /> Console.WriteLine(account2.Balance);<br /><br /><br /> Console.ReadLine();<br /> }<br /> }<br />}ryzamhttps://www.blogger.com/profile/08948488698923418322noreply@blogger.com