<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dulakshi Soysa on Medium]]></title>
        <description><![CDATA[Stories by Dulakshi Soysa on Medium]]></description>
        <link>https://medium.com/@dhnavd?source=rss-5b4b89e9eb23------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*fJf4LrKEKxjgkWbhVRdIZw.jpeg</url>
            <title>Stories by Dulakshi Soysa on Medium</title>
            <link>https://medium.com/@dhnavd?source=rss-5b4b89e9eb23------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 14:34:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dhnavd/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Clean Architecture and Domain Driven Design]]></title>
            <link>https://dhnavd.medium.com/clean-architecture-and-domain-driven-design-f4171786c0ed?source=rss-5b4b89e9eb23------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4171786c0ed</guid>
            <dc:creator><![CDATA[Dulakshi Soysa]]></dc:creator>
            <pubDate>Thu, 12 Feb 2026 11:56:36 GMT</pubDate>
            <atom:updated>2026-02-12T11:56:36.857Z</atom:updated>
            <content:encoded><![CDATA[<p>Clean Architecture and Domain‑Driven Design (DDD) are powerful tools for building systems that stay understandable and adaptable as they grow.</p><h3>Clean architecture :</h3><p><strong>Clean Architecture</strong> is a way of structuring your code so that <strong>business logic is at the centre</strong> and all technical details sit at the edges.</p><h4>A typical layering:</h4><ul><li><strong>Domain</strong><br>Pure business model: aggregates, entities, value objects, domain services n.</li><li><strong>Application (use case layer)</strong><br>Implements use cases such as coordinate domain logic and talks to abstractions (ports).</li><li><strong>Infrastructure (adapters)</strong><br>Databases, message brokers, HTTP clients, file storage, etc.<br>Implements the ports defined in the inner layers.</li><li><strong>Presentation</strong><br>Controllers, API endpoints, or other user‐facing adapters.</li></ul><p>In practice:</p><ul><li>The domain <strong>does not</strong> depend on EF, HTTP, AWS SDKs, or UI frameworks.</li><li>Infrastructure depends on domain/application, <strong>not the other way around</strong>.</li><li>Mapping and I/O concerns live at the edges, not inside domain entities.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j9wYr_4zkEhAj3n7WnBOsw.png" /></figure><h3>Domain Driven Design :</h3><p><strong>Domain-Driven Design (DDD)</strong> is an approach to building software for complex domains by making the <strong>business domain the central focus</strong> of your design and code.</p><h4>Key concepts:</h4><ul><li><strong>Ubiquitous language</strong><br>Use the same language in code that domain experts use in conversation. The terms stay consistent across conversations, tickets, and implementation.</li><li><strong>Bounded contexts</strong><br>Split the system into <strong>coherent subdomains</strong> that each have their own model and language.</li><li><strong>Aggregates &amp; invariants</strong><br>Group data and behavior into aggregates that <strong>enforce rules </strong>that are specific to each domain.</li><li><strong>Domain events</strong><br>Capture significant business facts explicitly for business.</li></ul><p>This keeps <strong>core business rules in one place</strong>, instead of scattering them across controllers, helpers, and SQL.</p><h3>Why Invest on this?</h3><p>As systems evolve, familiar symptoms appear:</p><ul><li>Every change touches <strong>too many places</strong></li><li>Core business rules are <strong>duplicated or inconsistent</strong></li><li>“Just adding a field” breaks unrelated parts of the system</li><li>Framework or infrastructure changes feel <strong>risky</strong></li></ul><p>DDD and Clean Architecture address these problems from two angles:</p><ul><li><strong>DDD</strong> shapes the <strong>business model and boundaries</strong></li><li><strong>Clean Architecture</strong> shapes the <strong>technical structure and dependency direction</strong></li></ul><p>Used together, they help you keep the codebase <strong>aligned with the domain</strong> and <strong>resilient to change</strong>.</p><h4>How can we use this :</h4><ul><li><strong>DDD decides the <em>what</em> and <em>where</em></strong></li><li>What are the <strong>bounded contexts</strong>?</li><li>What are the <strong>aggregates</strong> and <strong>invariants</strong>?</li><li>Where do particular rules and decisions live?</li><li><strong>Clean Architecture decides the <em>how</em></strong></li><li>How do we <strong>structure layers</strong> within a context?</li><li>How do <strong>dependencies flow</strong>?</li><li>Where do we place <strong>infrastructure</strong> and integration logic?</li></ul><p>You can picture each bounded context as its <strong>own Clean Architecture “onion”</strong>:</p><ul><li>Inner circle: the DDD domain model for that context</li><li>Outer circles: application, infrastructure, presentation</li></ul><h4>Questions you might ask yourself when taking this approach :</h4><ul><li>Is it clear which <strong>bounded context</strong> this belongs to?</li></ul><blockquote>Clarify the domain and avoid dropping code into a generic shared module.</blockquote><ul><li>Does the change map to a clear <strong>use case</strong>?</li></ul><blockquote>Introduce a use‑case class instead of adding logic to controllers.</blockquote><ul><li>Are business rules captured in the <strong>domain model</strong>, not controllers/services?</li></ul><blockquote>Move invariants and decision logic into aggregates/value objects.</blockquote><ul><li>Do dependencies <strong>point inward</strong> toward domain and application layers?</li></ul><blockquote>Remove references from core code to infrastructure/frameworks; add ports where needed.</blockquote><ul><li>Can you test the core behavior without <strong>DB or HTTP</strong>?</li></ul><blockquote>Extract logic into domain/use‑case layers and inject ports.</blockquote><ul><li>Is the <strong>boundary</strong> to other contexts explicit (APIs/events/contracts), not implicit (shared DB)</li></ul><blockquote><em>Replace cross‑context DB access with well‑defined contracts over time.</em></blockquote><h4>However, there are common Pitfalls you may fall into</h4><ol><li><strong>Anemic domain models</strong></li></ol><ul><li>Domain entities only hold data; all logic lives in services.</li><li>Improve by moving rules and decisions into aggregates and value objects.</li></ul><p><strong>2. Domain depending on infrastructure</strong></p><ul><li>Entities call HTTP clients, run SQL, or know about Kafka topics.</li><li>Push these concerns into adapters; expose them only via ports.</li></ul><p><strong>3. Over‑engineering too early</strong></p><ul><li>Heavy layering and many abstractions around trivial CRUD screens.</li><li>Match the level of structure to the <strong>complexity and lifetime</strong> of the feature.</li></ul><p><strong>4. “Common” or “shared” modules that cut across everything</strong></p><ul><li>Common, Shared, or Utils projects with broad dependencies.</li><li>Consolidate truly shared <em>domain</em> concepts into a carefully designed shared kernel; avoid dumping grounds.</li></ul><p><strong>5. Ignoring organisational reality</strong></p><ul><li>A perfectly “pure” architecture that doesn’t match team skills, deployment practices, or operational constraints.</li><li>Adapt patterns to your environment; use them to guide decisions, not to impose dogma</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4171786c0ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unity Container in .net Application]]></title>
            <link>https://dhnavd.medium.com/unity-container-in-net-application-a9548adbd0a1?source=rss-5b4b89e9eb23------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9548adbd0a1</guid>
            <dc:creator><![CDATA[Dulakshi Soysa]]></dc:creator>
            <pubDate>Sun, 06 Jun 2021 06:07:10 GMT</pubDate>
            <atom:updated>2021-06-06T06:07:10.666Z</atom:updated>
            <content:encoded><![CDATA[<h3>Unity Container in .net Application</h3><p>Unity Containers are used in .Net application for many purposes. this is an lightweight and Extensible IOC Container for .Net Applications supported by Microsoft.</p><p><strong>What is IOC container ?</strong></p><p>A framework for implementing automatic Dependency Injection. this basically manages object creation, its life span and injection of this object to the classes.</p><p>these container creates an object of the specified class and also injects all the dependency objects through a constructor, a property or a method at run time and disposes it at the appropriate time. This is done so that we don’t have to create and manage objects manually.</p><p>All the containers must provide easy support for the following Dependency Injection lifecycle.</p><ul><li>Register: The container needs to know what dependencies to create when it encounters a particular type. This process is called registration. Basically, it should include a way to write type mappings<strong>.</strong></li><li>Resolve: When using the IoC container, there is no need to create objects manually. The container did it for us. This is called permission. The container must contain some methods to resolve the specified type. The container creates an object of the specified type, injects any necessary dependencies, and then returns the object.</li><li>Dispose: The container must manage the lifetime of the dependent objects. Most IoC containers include different lifetime managers to manage an object’s lifecycle and dispose it.</li></ul><p>Unity is one of the IoC container available for .net there are many commercial and open source available.</p><h3>Unit y Container Features:</h3><ul><li>Simplified type-mapping registration for interface type or base type.</li><li>Supports registration of an existing instance.</li><li>Supports code-based registration as well as design time registration.</li><li>Automatically injects registered type at runtime through a constructor, a property or a method.</li><li>Supports deferred resolution.</li><li>Supports nested containers.</li><li>Automatic disposing of instances based on lifetime managers; lifetime managers include hierarchical, per resolve, externally controlled, per request and per thread.</li><li>Supports service location capability; this allows clients to store or cache the container.</li><li>Supports type interception and instance interception.</li><li>Easy to extend.</li></ul><h4>installing unity on a project</h4><p>first create a project and add unity through the Nuget package manager. (you can manage nuget packages when you right click on project and click on manage nuget packages) this will inject some libraries into the solution as references.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*aeKk-HI62ETmHnZs1s_UPQ.png" /></figure><h4>Register and resolve -&gt; Unity</h4><p>lets consider the scenario of a calculating the calories of some food.then our program me will be as such</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*Rtk4Rpzu0X5lJ22rJH7b4A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*Hr_3VgTRINtxMJSZln2cZA.png" /></figure><p>In the above example, I created and passed an object of <strong><em>Apple </em></strong>while creating an object of the <strong><em>CalculateCalorie </em></strong>class. Thus, i injected the dependency of the <strong><em>CalculateCalorie </em></strong>class manually. Now, ill show how to use Unity container to understand different ways to register and resolve dependencies.</p><p>In order to use Unity container, we first need to create an object of it. You can use any class which implements the <strong><em>IUnityContainer </em></strong>interface. Unity container includes the <strong><em>UnityContainer </em></strong>class in the <strong><em>Microsoft.Practices.Unity</em></strong> namespace that implements the <strong><em>IUnityContainer </em></strong>interface.</p><pre>IUnityContainer container = new UnityContainer();<br><br>container.RegisterType&lt;IFood, Apple&gt;();</pre><p>now lets see about resolving,</p><pre>IUnityContainer container = new UnityContainer();<br>container.RegisterType&lt;IFood, Apple&gt;();// Map IFood with Apple<br><br>//Resolves dependencies and returns the Driver object <br>CalculateCalorie cal= container.Resolve&lt;CalculateCalorie&gt;(); <br>cal.CalculateCalorie();</pre><p>Unity container will create a new object and inject it every time we resolve the same type.</p><h4>Multiple Registering</h4><pre>IUnityContainer container = new UnityContainer();<br>container.RegisterType&lt;IFood, Apple&gt;();<br>container.RegisterType&lt;IFood, Banana&gt;();<br><br>CalculateCalorie cal= container.Resolve&lt;CalculateCalorie&gt;();<br>cal.CalculateCalorie();</pre><h3>Register Named Type</h3><pre>IUnityContainer container = new UnityContainer();<br>container.RegisterType&lt;IFood, Apple&gt;();<br>container.RegisterType&lt;IFood, Banana&gt;(&quot;YellowFruit&quot;);<br><br>IFood apple = container.Resolve&lt;IFood&gt;();  // returns the Apple object<br>IFood banana = container.Resolve&lt;IFood&gt;(&quot;YellowFruit&quot;); // returns the Banana object</pre><h3>Register Instance</h3><pre>var container = new UnityContainer();<br>IFood apple = new Apple();<br>container.RegisterInstance&lt;IFood&gt;(audi);<br><br>CalculateCalorie cal1= container.Resolve&lt;CalculateCalorie&gt;();<br>cal1.CalculateCalorie();<br>cal1.CalculateCalorie();<br><br>CalculateCalorie cal2= container.Resolve&lt;CalculateCalorie&gt;();<br>cal2.CalculateCalorie();</pre><p>Unity container allows us to register an existing instance using the RegisterInstance() method. It will not create a new instance for the registered type and we will use the same instance every time.</p><h3>Constructor Injection</h3><p>Unity container will inject dependencies via the constructor.</p><pre>var container = new UnityContainer();<br>container.RegisterType&lt;IFood, Apple&gt;();<br><br>var cal= container.Resolve&lt;CalculateCalorie&gt;();<br>cal.CalculateCalorie();</pre><p>whenever Unity container needs to inject an object of type IFood, it will create and inject an object of the Appleclass. The container.Resolve&lt;CalculateCalorie&gt;() method will create and return an object of the CalculateCalorieclass by passing an object of IFoodinto the constructor.</p><p>there are 3 other ways to use unity injection.</p><h4>Property Injection</h4><p>Property injection in Unity container can be implemented in two ways:</p><ol><li>Using the [Dependency] attribute</li></ol><p>For the property injection, we first tell the Unity container which property to inject. So, we need to decorate the dependent properties with the [Dependency] attribute</p><ol><li>Using run-time configuration</li></ol><p>Unity container allows us to configure a property injection with the RegisterType() method if a method is not marked with the [Dependency] attribute. You can pass an object of the <a href="https://msdn.microsoft.com/en-us/library/microsoft.practices.Unity.injectionproperty.aspx">InjectionProperty</a> class in the RegisterType() method to specify a property name and a parameter value.</p><h4>Method Injection</h4><p>In the method injection, dependencies are provided through method parameters.</p><p>Method injection in Unity can be implemented in two ways:</p><ol><li>Using the [InjectionMethod] attribute</li><li>Using run-time configuration</li></ol><h4>Overrides</h4><p>Unity container allows us to override a registered type by using ResolverOverride. The ResolverOverride is an abstract class that provides implementation for overriding registration. There are three important classes which inherit ResolverOverride:</p><ol><li>ParameterOverride: Used to override constructor parameters.</li><li>PropertyOverride: Used to override the value of a specified property.</li><li>DependencyOverride: Used to override the type of dependency and its value.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9548adbd0a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Logging Using NLog, How to use Structured logs in C# .net]]></title>
            <link>https://dhnavd.medium.com/logging-using-nlog-how-to-use-structured-logs-in-c-net-6bc581145b1a?source=rss-5b4b89e9eb23------2</link>
            <guid isPermaLink="false">https://medium.com/p/6bc581145b1a</guid>
            <dc:creator><![CDATA[Dulakshi Soysa]]></dc:creator>
            <pubDate>Mon, 09 Mar 2020 17:40:29 GMT</pubDate>
            <atom:updated>2020-03-09T17:40:29.546Z</atom:updated>
            <content:encoded><![CDATA[<h3>Logging Using NLog, How to use Structured logs in C# .net</h3><p>First of all lets find out what Application logs are?</p><p>An application log is a file where we can store events to errors to anything that we need in application level. it can be :</p><ul><li>Warnings about low disk space</li><li>An operation that has been carried out</li><li>Any significant problems — known as an error events — that prevent the application from starting</li><li>A success audit to indicate a security event such as a successful logon</li><li>A failure audit to indicate an event such as a logon failure</li><li>information that we have to save for later purposes(Objects.. etc)</li></ul><p>I will demonstrate specifically about structured logs because this method can be used to investigate what can be happen in application level while user is using the system.</p><p>for example, if user report that there is a error occurring and if the developer really cant identify the problem and what has happen. These structured logs can be used to identify exactly what might have caused the problem.</p><p><strong>what are Structured Logs?</strong></p><p>before digging into that, we have to have a knowledge about what is structured and unstructured ,</p><p>Structured : usually rides with relational database(RDBMS), fields store length-delibeated data phone numbers, Social Security numbers, or Zip Codes.</p><p>Unstructured : essentially everything else. Unstructured data has internal strcture but is not structured via pre-defined data models or schema.</p><p>now moving on to structured logs, as developers our most valuable asset is logs when it comes to investigate a problem occurred in a system. if something go south our first impression is to look for the logs. there are mainly two types of logs we look for in C#, .net applications. one is IIS Logs and other is Nlog or similar.</p><p>IIS are mainly server logs and we cant get a clear picture from this if the request went through without a problem. but with Nlogs, we can do more.</p><p>there are mainly two user scenarios for structured logs:</p><ol><li>Process log files for analytics or business intelligence — A good example of this would be processing web server logs and doing some stigmatization and aggregates across the data.</li><li>Searching Log files — Being able to search and correlate log messages is very valuable to development teams during the development process and troubleshooting the production problems.</li></ol><h4>Write Structured Logging with NLog:</h4><p>@ will format the object as Json.</p><p>$ is string format.</p><pre>logger.Info(&quot;Test {value1}&quot;, o); // null case. Result:  Test NULL<br>logger.Info(&quot;Test {value1}&quot;, new DateTime(2018,03, 25)); // datetime case. Result:  Test 25-3-2018 00:00:00 (locale TString)<br>logger.Info(&quot;Test {value1}&quot;, new List&lt;string&gt; { &quot;a&quot;, &quot;b&quot; }); // list of strings. Result: Test &quot;a&quot;, &quot;b&quot;<br>logger.Info(&quot;Test {value1}&quot;, new[] { &quot;a&quot;, &quot;b&quot; }); // array. Result: Test &quot;a&quot;, &quot;b&quot;<br>logger.Info(&quot;Test {value1}&quot;, new Dictionary&lt;string, int&gt; { { &quot;key1&quot;, 1 }, { &quot;key2&quot;, 2 } }); // dict. Result:  Test &quot;key1&quot;=1, &quot;key2&quot;=2</pre><pre>var order = new Order<br>{<br>    OrderId = 2,<br>    Status = OrderStatus.Processing<br>};</pre><pre>logger.Info(&quot;Test {value1}&quot;, order); // object Result:  Test MyProgram.Program+Order<br>logger.Info(&quot;Test {@value1}&quot;, order); // object Result:  Test {&quot;OrderId&quot;:2, &quot;Status&quot;:&quot;Processing&quot;}<br>logger.Info(&quot;Test {value1}&quot;, new { OrderId = 2, Status = &quot;Processing&quot;}); // anomynous object. Result: Test { OrderId = 2, Status = Processing }<br>logger.Info(&quot;Test {@value1}&quot;, new { OrderId = 2, Status = &quot;Processing&quot;}); // anomynous object. Result:Test {&quot;OrderId&quot;:2, &quot;Status&quot;:&quot;Processing&quot;}</pre><pre>logger.info(&quot;Test value 1 : @value1&quot;\n&quot; Test value 2 ; @value2&quot;, new {userid = 1, name = &quot;mike&quot;}, new {grade = &quot;A&quot;, subject = &quot;Maths&quot;})</pre><p>NLog 4.5 makes it easier to catch and preserveevent logproperties.</p><p>for more information please refer — <a href="https://github.com/NLog/NLog/wiki/EventProperties-Layout-Renderer">https://github.com/NLog/NLog/wiki/EventProperties-Layout-Renderer</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6bc581145b1a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>