<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Anas AbdelHadi</title>
    <description>The latest articles on DEV Community by Anas AbdelHadi (@anas-abdelhadi).</description>
    <link>https://dev.to/anas-abdelhadi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2624280%2Feb61a5fa-3182-4246-b46e-eea762890842.png</url>
      <title>DEV Community: Anas AbdelHadi</title>
      <link>https://dev.to/anas-abdelhadi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anas-abdelhadi"/>
    <language>en</language>
    <item>
      <title>[Boost]</title>
      <dc:creator>Anas AbdelHadi</dc:creator>
      <pubDate>Wed, 01 Jan 2025 14:32:32 +0000</pubDate>
      <link>https://dev.to/anas-abdelhadi/-g0c</link>
      <guid>https://dev.to/anas-abdelhadi/-g0c</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/anas-abdelhadi" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2624280%2Feb61a5fa-3182-4246-b46e-eea762890842.png" alt="anas-abdelhadi"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/anas-abdelhadi/dtos-in-typescript-2cik" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Corello, Simple Dtos in FrontEnd&lt;/h2&gt;
      &lt;h3&gt;Anas AbdelHadi ・ Jan 1&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#typescript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#react&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#vue&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#frontend&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>typescript</category>
      <category>frontend</category>
      <category>webdev</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Corello, Simple Dtos in FrontEnd</title>
      <dc:creator>Anas AbdelHadi</dc:creator>
      <pubDate>Wed, 01 Jan 2025 13:59:31 +0000</pubDate>
      <link>https://dev.to/anas-abdelhadi/dtos-in-typescript-2cik</link>
      <guid>https://dev.to/anas-abdelhadi/dtos-in-typescript-2cik</guid>
      <description>&lt;p&gt;Data Transfer Objects (DTOs) are a pivotal part of modern application architecture. They simplify communication between different layers of an application, ensuring that data integrity and structure are maintained. This article explores the concept of DTOs, their importance, best practices, and how the &lt;strong&gt;Corello&lt;/strong&gt; library revolutionizes serialization and deserialization in TypeScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are DTOs?
&lt;/h2&gt;

&lt;p&gt;DTOs, short for Data Transfer Objects, are simple objects designed to transfer data without any business logic. They act as containers for transferring structured information across application boundaries—whether between an API and a client, or within different layers of an application such as controllers, services, or repositories.&lt;/p&gt;

&lt;p&gt;The core idea is abstraction. DTOs abstract away implementation-specific details, presenting only the relevant data needed by the consuming system. This decoupling ensures flexibility, maintainability, and clarity in code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Do We Need DTOs?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Decoupling Layers:&lt;/strong&gt; DTOs create a clear contract between different layers, allowing for independent evolution without breaking existing interactions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance Optimization:&lt;/strong&gt; By shaping data explicitly, DTOs ensure only required information is transferred, minimizing payload size.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data Validation and Security:&lt;/strong&gt; They prevent over-posting attacks and enforce constraints by limiting exposed properties.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simplified Testing:&lt;/strong&gt; DTOs make it easier to mock and test data-related interactions, as they’re typically devoid of complex logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best Practices for DTOs
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Keep It Simple:&lt;/strong&gt; DTOs should be lean, containing only fields required for the operation. Avoid embedding unnecessary business logic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Explicit Typing:&lt;/strong&gt; In TypeScript, leverage interfaces and type annotations to ensure the structure is well-defined and predictable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Separate DTOs by Use Case:&lt;/strong&gt; Create different DTOs for different operations (e.g., CreateUserDto, UpdateUserDto) to avoid ambiguity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Automate Serialization:&lt;/strong&gt; Avoid manual mapping; instead, use tools or libraries to handle nested and complex data structures efficiently.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enter Corello: Streamlining DTO Management
&lt;/h2&gt;

&lt;p&gt;Corello takes the complexity out of DTO serialization and deserialization in TypeScript. By providing powerful decorators and utilities, it empowers developers to handle nested object hierarchies with minimal effort.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i corello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key Features of Corello&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Auto Type Instantiation&lt;/strong&gt;&lt;br&gt;
If you initialize the property with a concrete instance, then your Dto will know how to serialize it without decorator hints.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public someUser = new User()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;@Dto Decorator&lt;/strong&gt;&lt;br&gt;
The &lt;code&gt;@Dto&lt;/code&gt; decorator transforms a plain class into a DTO. It ensures seamless serialization by providing a built-in from method for deserializing JSON into strongly typed objects.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Dto
class User extends DtoBase&amp;lt;User&amp;gt; {
    name!: string;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const user = new User({ name: 'John Doe' })
console.log(user.name); // Output: John Doe

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;a class="mentioned-user" href="https://dev.to/class"&gt;@class&lt;/a&gt; Decorator&lt;/strong&gt;&lt;br&gt;
This decorator explicitly defines the type of a property, making nested object serialization effortless.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Dto
class Car extends DtoBase&amp;lt;Car&amp;gt;{
    @Class(() =&amp;gt; User)
    owner!: User;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;@Factory Decorator&lt;/strong&gt;&lt;br&gt;
Designed for collections, &lt;code&gt;@Factory&lt;/code&gt; gives developers control over how each item in an array or collection is instantiated during deserialization.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Dto
class Car extends DtoBase&amp;lt;Car&amp;gt; {
    @Factory((data) =&amp;gt; new User(data))
    passengers: User[] = [];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;DtoBase&lt;/strong&gt;&lt;br&gt;
Extending &lt;code&gt;DtoBase&lt;/code&gt;simplifies the use of DTOs by introducing methods like from and enabling custom serialization logic for specific scenarios.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Dto
class User extends DtoBase&amp;lt;User&amp;gt; {
    name!: string;
}

const user = new User().from({ name: 'Alice' });
console.log(JSON.stringify(user));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why Corello Stands Out
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Corello&lt;/strong&gt; eliminates the repetitive boilerplate code often associated with managing DTOs. By offering:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Type-Safe Serialization:&lt;/strong&gt; Ensures that nested structures and primitive types are handled gracefully.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ease of Use:&lt;/strong&gt; Decorators abstract away the complexities of manual mapping.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Flexible Configuration:&lt;/strong&gt; From primitive values to complex nested objects and arrays, &lt;code&gt;Corello&lt;/code&gt; adapts to your needs.&lt;/p&gt;

&lt;p&gt;The inclusion of JSON.stringify support (including getters unless prefixed with _) makes it developer-friendly and ideal for real-world scenarios.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example in Action
&lt;/h2&gt;

&lt;p&gt;Here’s a glimpse of &lt;code&gt;Corello&lt;/code&gt;in action:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import { Class, Factory, Dto, DtoBase } from 'corello';

@Dto
class User extends DtoBase&amp;lt;User&amp;gt; {
   name!: string;
}

@Dto
class Car extends DtoBase&amp;lt;Car&amp;gt; {
   @Class(() =&amp;gt; User)
   driver!: User;

   @Factory((data) =&amp;gt; new User(data))
   passengers: User[] = [];
}

const car = new Car().from({
   driver: { name: 'John' },
   passengers: [{ name: 'Jane' }, { name: 'Doe' }],
});

console.log(JSON.stringify(car));

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;DTOs are an indispensable tool for ensuring clarity, security, and efficiency in data handling. &lt;code&gt;Corello&lt;/code&gt; takes this a step further, simplifying the serialization process and giving developers the tools they need to manage complex object hierarchies effortlessly.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;Corello&lt;/code&gt;, your DTOs become more than just data containers—they’re a testament to the elegance and power of well-architected TypeScript code. So why wait? Install &lt;code&gt;Corello&lt;/code&gt;today and elevate your application development experience!&lt;/p&gt;

&lt;h2&gt;
  
  
  Sample Project
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/Anas-Abdelhadi/corello" rel="noopener noreferrer"&gt;You can check out the sample usage here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>react</category>
      <category>vue</category>
      <category>frontend</category>
    </item>
    <item>
      <title>FrontEnd Dependency Injection with iocello</title>
      <dc:creator>Anas AbdelHadi</dc:creator>
      <pubDate>Sat, 28 Dec 2024 12:29:37 +0000</pubDate>
      <link>https://dev.to/anas-abdelhadi/mastering-dependency-injection-with-iocello-3j97</link>
      <guid>https://dev.to/anas-abdelhadi/mastering-dependency-injection-with-iocello-3j97</guid>
      <description>&lt;p&gt;Welcome to &lt;strong&gt;iocello&lt;/strong&gt;, a library that simplifies the concepts of &lt;strong&gt;Dependency Injection (DI)&lt;/strong&gt; and &lt;strong&gt;Inversion of Control (IoC)&lt;/strong&gt; in your applications. With iocello, you can dynamically manage your application’s dependencies and domains while maintaining flexibility and control.&lt;/p&gt;

&lt;p&gt;In this tutorial, we’ll explore the key concepts of iocello, walk through its setup, and demonstrate how to use it effectively.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;The Concept&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Imagine your application as a &lt;strong&gt;library&lt;/strong&gt; of bookshelves. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Shelves (Domains)&lt;/strong&gt;: Each shelf represents a domain, and the lowest shelf (domain) is numbered &lt;code&gt;0&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Books (Classes/Services)&lt;/strong&gt;: Books are your injectable classes or services, which can be stored on any shelf.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cross-Referencing&lt;/strong&gt;: At runtime, you can fetch and construct books (instances of classes) from the current domain or any specified domain.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tagging and Customization&lt;/strong&gt;: When registering a book (class), you assign it a unique tag and specify the shelf (domain) where it belongs. This ensures easy management and retrieval.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inversion of Control&lt;/strong&gt;: You can dynamically change the container (shelf/domain) where books are fetched from, using &lt;code&gt;ioc.setContainerDomain()&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Setup&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To get started with iocello, install the package and set up your environment:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Installation&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;iocello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will also need to install the shared kernel corello&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;corello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Basic Usage&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Mark Classes as Injectable&lt;/strong&gt;: Use the &lt;code&gt;@Service&lt;/code&gt; decorator.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inject Dependencies&lt;/strong&gt;: Use the &lt;code&gt;@Inject&lt;/code&gt; decorator for properties in your classes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Register Services&lt;/strong&gt;: Add services to the IoC container using &lt;code&gt;ioc.add(ServiceClass)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Instantiation&lt;/strong&gt;: Use &lt;code&gt;ioc.construct&amp;lt;Type&amp;gt;(TagName, domain?)&lt;/code&gt; to create instances dynamically.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Example: Building with iocello&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let’s create an example application with &lt;code&gt;Pet&lt;/code&gt; and &lt;code&gt;Person&lt;/code&gt; services.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: Create Services&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Service&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Inject&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;iocello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define the Pet class and mark it as a service&lt;/span&gt;
&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Service&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Pet&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Pet&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Inject a dependency of type Person from domain 1&lt;/span&gt;
  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Inject&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Person&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;domain&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;walk&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;PET IS WALKING&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;dispose&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Add the Pet service to the IoC container&lt;/span&gt;
&lt;span class="nx"&gt;ioc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Pet&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: Cross-Referencing with Injection&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Service&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Person&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Inject an instance of Pet from domain 1 with a custom name&lt;/span&gt;
  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Inject&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;domain&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Pet&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="nx"&gt;semsem&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Pet&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;dispose&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Step 3: Enforcing Domain Rules&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;You can replace a service at a specific domain by using the &lt;code&gt;enforce&lt;/code&gt; property:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Service&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Person&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;enforce&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;domain&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Person2&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;inject&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="nx"&gt;Pet&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Pet&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;dispose&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Step 4: Constructing and Using Instances&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now that our services are registered, we can create and use them dynamically:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;ioc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;ioc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Person2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Construct an instance of Person from domain 100&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ioc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;construct&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Person&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Person&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Use the dynamically injected properties&lt;/span&gt;
&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Pet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;walk&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: PET IS WALKING&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Key Features of iocello&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Domain-Specific Injection&lt;/strong&gt;: Fetch instances from specific domains using tags.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Replacement&lt;/strong&gt;: Services can override others in a domain using the &lt;code&gt;enforce&lt;/code&gt; property.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Circular Dependency Handling&lt;/strong&gt;: iocello resolves circular dependencies automatically.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Warnings and Logs&lt;/strong&gt;: Alerts for missing services or unintended overwrites.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Tips and Best Practices&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use Tags Wisely&lt;/strong&gt;: Ensure tags are unique for each service to avoid conflicts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dispose Resources&lt;/strong&gt;: Implement the &lt;code&gt;dispose&lt;/code&gt; method in services for proper cleanup.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Monitor Logs&lt;/strong&gt;: Watch for warnings about missing services or overwrites to debug effectively.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;With &lt;strong&gt;iocello&lt;/strong&gt;, managing dependencies becomes intuitive and scalable. By organizing your services into domains and leveraging dynamic instantiation, you can achieve a clean, maintainable architecture for your applications. Whether you're building a simple project or a complex enterprise application, iocello empowers you to take control of your IoC needs effortlessly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Anas-Abdelhadi/iocello" rel="noopener noreferrer"&gt;Check out source code for the sample application (Vue+vite) &lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy coding! 🎉&lt;/p&gt;

</description>
      <category>ioc</category>
      <category>dependecyinjection</category>
      <category>typescript</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
