{"id":94749,"date":"2023-08-09T08:00:15","date_gmt":"2023-08-09T06:00:15","guid":{"rendered":"https:\/\/code-maze.com\/?p=94749"},"modified":"2023-08-09T22:52:32","modified_gmt":"2023-08-09T20:52:32","slug":"csharp-moduleinitializer-attribute","status":"publish","type":"post","link":"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/","title":{"rendered":"ModuleInitializer Attribute in C#"},"content":{"rendered":"<p>As a C# developer, you might have overlooked the ModuleInitializer attribute introduced in version 9 of the language. This attribute is a hidden gem in the extensive BCL APIs and <strong>designates a method that the runtime should first invoke when loading the assembly<\/strong>. Before delving into its practical application in class library projects, let&#8217;s clarify the difference between a module and an assembly.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/csharp-advanced-topics\/ModuleInitializerAttributeInCSharp\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>Let&#8217;s start.<\/p>\n<h2>Module vs Assembly<\/h2>\n<p>To understand the core difference between a module and an assembly, it is important to note that <strong>a module cannot be deployed independently; instead, it is always part of an assembly.<\/strong><\/p>\n<p>On the other hand, an assembly serves as a logical unit that contains one or more modules and includes additional metadata that describes the types, resources, and references within the assembly. As the primary building block of a .NET application, an assembly provides the necessary information for the runtime to load and execute code.\u00a0<\/p>\n<p>In this context, we can consider a class within an assembly as a module. We can apply the <code>ModuleInitializer<\/code> attribute to any method within that class, provided that the method fulfills specific prerequisites.<\/p>\n<p>Let&#8217;s explore these prerequisites.<\/p>\n<h2>Rules of a ModuleInitializer Attribute Marked Method<\/h2>\n<p>To consider a method as a module initialization method, it must meet the following conditions:<\/p>\n<ul>\n<li>The method must be <code>static<\/code><\/li>\n<li>It should not have any parameters<\/li>\n<li>The method&#8217;s signature must be either <code>void<\/code> or <code>async void<\/code><\/li>\n<li>It cannot be generic or reside within a generic type<\/li>\n<li>The method must be accessible through the module&#8217;s <code>public<\/code> or <code>internal<\/code> access modifiers<\/li>\n<\/ul>\n<p>Now that we have an understanding of what qualifies a method to be a module initializer, let&#8217;s delve into its application in a class library project.<\/p>\n<h2>How to Use the ModuleInitializer Attribute in a Class Library<\/h2>\n<p>The <a href=\"https:\/\/code-maze.com\/dependency-injection-aspnet\/\" target=\"_blank\" rel=\"noopener\">dependency injection<\/a> principle is important for writing clean and loosely coupled code. We register our dependencies at the startup or entry point of the application. However, class library projects do not have a startup or entry point. To mitigate this, we can create extension methods to register dependencies for the classes used in the project. We can then invoke these extension methods in the application startup.<\/p>\n<p><strong>However, this implementation requires exposing contracts or interfaces to the library&#8217;s consumer<\/strong> (the application with the startup class), which is a flaw. What happens if our library&#8217;s consumer is another class library project, such as a Unit Test project?<\/p>\n<p>Let&#8217;s see how we can overcome this limitation with the help of the ModuleInitiailizer attribute by doing a mock implementation of the <code>Notification<\/code> component, which can send SMS or Email.\u00a0<\/p>\n<p>Firstly, we must add the required NuGet package to use Dependency Injection in our class library project:<\/p>\n<p>\u00a0<code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">dotnet add package Microsoft.Extensions.DependencyInjection<\/code>\u00a0<\/p>\n<p>With the dependency now installed, let&#8217;s move ahead and create our interface responsible for sending notifications:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">namespace MessagingLibrary;\r\n\r\ninternal interface INotification\r\n{\r\n    string SendNotification();\r\n}<\/pre>\n<p>We define an interface <code>INotification<\/code> with <code>internal<\/code> access modifier, as we must hide our internal implementation from the library&#8217;s consumers. This interface provides a contract for implementing classes to send notifications and includes a <code>SendNotification()<\/code> method that returns a string.\u00a0<\/p>\n<p>We can proceed with implementing the <code>INotification<\/code> interface now:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">namespace MessagingLibrary;\r\n\r\ninternal class Email : INotification\r\n{\r\n    public string SendNotification()\r\n    {\r\n        return \"Sending Email\";\r\n    }\r\n}\r\n\r\ninternal class Sms : INotification\r\n{\r\n    public string SendNotification()\r\n    {\r\n        return \"Sending SMS\";\r\n    }\r\n}<\/pre>\n<p>The <code>MessagingLibrary<\/code> namespace contains two <code>internal<\/code> classes, <code>Email<\/code> and <code>Sms<\/code>, which implements the <code>INotification<\/code> interface and provide unique implementations for the <code>SendNotification()<\/code> method.<\/p>\n<h3>Achieving Dependency Injection<\/h3>\n<p>Let&#8217;s move on to the Dependency Injection part and register the dependencies and decorate it with the <code>ModuleInitializer<\/code> attribute:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">internal static class DependenciesRegistration\r\n{\r\n    internal static ServiceProvider DependenciesProvider { get; private set; }\r\n\r\n    [ModuleInitializer]\r\n    [SuppressMessage(\"Usage\", \"CA2255:The \\'ModuleInitializer\\' attribute should not be used in libraries\",\r\n        Justification =\r\n            \"The consumer of the library is abstracted from this because of usage of Internal Access Modifier.\" +\r\n            \"Only used in this project for dependency registration.\")]\r\n    internal static void RegisterDependencies()\r\n    {\r\n        var services = new ServiceCollection();\r\n        services.AddScoped&lt;INotification, Sms&gt;();\r\n        services.AddScoped&lt;INotification, Email&gt;();\r\n        DependenciesProvider = services.BuildServiceProvider();\r\n    }\r\n}<\/pre>\n<p>The <code>RegisterDependencies()<\/code> method registers dependencies using the <code>ModuleInitializer<\/code> attribute. It abides by all the prerequisites for this attribute. It adds scoped dependencies for <code>INotification<\/code> implementations of <code>Sms<\/code> and <code>Email<\/code> to the <code>ServiceCollection<\/code>.<\/p>\n<p>The dependencies are built and stored in the <code>DependenciesProvider<\/code> property, allowing access to the registered dependencies within the assembly. <strong>As this method is decorated with the <code>ModuleInitializer<\/code> attribute, this method will be executed when the library gets loaded<\/strong>.<\/p>\n<p>Our internal implementation for sending notifications is complete. Now, we must create a public API for library consumers to use:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public class Notifier\r\n{\r\n    private readonly INotification? _notification;\r\n    private readonly IEnumerable? _notificationServiceLocator;\r\n    \r\n    public string NotificationResult { get; }\r\n\r\n    public Notifier(string notificationType)\r\n    {\r\n        _notificationServiceLocator = DependenciesRegistration.DependenciesProvider.GetServices();\r\n\r\n        if (_notificationServiceLocator is not null)\r\n            _notification = notificationType switch\r\n            {\r\n                \"sms\" =&gt; _notificationServiceLocator.OfType()&lt;Sms&gt;.FirstOrDefault(),\r\n                \"email\" =&gt; _notificationServiceLocator.OfType()&lt;Email&gt;.FirstOrDefault(),\r\n                _ =&gt; throw new ArgumentException(\"Invalid notification type\")\r\n            };\r\n        NotificationResult = _notification?.SendNotification()!;\r\n    }\r\n}<\/pre>\n<p>The <code>Notifier<\/code> class is responsible for sending notifications. In the constructor, we retrieve available implementations from the service provider and select the appropriate implementation based on the notification type using switch expression. Then we invoke the <code>SendNotification()<\/code> method on the implementation chosen. The result is stored in the <code>NotificationResult<\/code>\u00a0property.<\/p>\n<p>We have created a new public API for sending notifications, which separates our internal business logic from the library consumer. To test our library, we can now use unit tests to consume its APIs:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">namespace Tests;\r\n\r\npublic class NotifierUnitTest\r\n{\r\n    [Fact]\r\n    public void WhenSmsIsPassedAsParameter_ThenSmsMustBeSent()\r\n    {\r\n        var notifier = new Notifier(\"sms\"); \r\n        Assert.Equal(\"Sending SMS\", notifier.NotificationResult);\r\n    }\r\n\r\n    [Fact]\r\n    public void WhenEmailIsPassedAsParameter_ThenEmailMustBeSent()\r\n    {\r\n        var notifier = new Notifier(\"email\");\r\n        Assert.Equal(\"Sending Email\", notifier.NotificationResult);\r\n    }\r\n\r\n    [Fact]\r\n    public void WhenInvalidParameterIsPassed_ThenExceptionMustBeThrown()\r\n    {\r\n        Assert.Throws&lt;ArgumentException&gt;(() =&gt; new Notifier(\"invalid\"));\r\n    }\r\n}<\/pre>\n<p>These test methods cover different scenarios to ensure that the <code>Notifier<\/code> class behaves correctly when different notification types are provided as parameters. The tests help ensure the expected behavior of the <code>Notifier<\/code> class and provide confidence in its functionality. All the tests are green, proving our approach works.<\/p>\n<p>By utilizing the ModuleInitalizer attribute, we were able to initiate the code within the method where all dependencies were registered with the service provider.<strong> This accomplishment would not have been feasible without the use of this attribute since the class library lacks an entry point.<\/strong><\/p>\n<h2>Conclusion<\/h2>\n<p>We&#8217;ve learned how to use the ModuleInitializer attribute on a method that the runtime executes when loading an assembly. This attribute can be helpful for executing initialization code in projects that lack entry points, such as class libraries.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a C# developer, you might have overlooked the ModuleInitializer attribute introduced in version 9 of the language. This attribute is a hidden gem in the extensive BCL APIs and designates a method that the runtime should first invoke when loading the assembly. Before delving into its practical application in class library projects, let&#8217;s clarify [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":62189,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[12],"tags":[22,1117,1811,536,1904],"class_list":["post-94749","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-csharp","tag-net-core","tag-attribute","tag-c","tag-dependency-injection","tag-moduleinitializer","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>ModuleInitializer Attribute in C#<\/title>\n<meta name=\"description\" content=\"In this article, we discuss the overlooked ModuleInitializer attribute in C# and showcase its use in a class library.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ModuleInitializer Attribute in C#\" \/>\n<meta property=\"og:description\" content=\"In this article, we discuss the overlooked ModuleInitializer attribute in C# and showcase its use in a class library.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-09T06:00:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-09T20:52:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Code Maze\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Code Maze\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/\"},\"author\":{\"name\":\"Code Maze\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\"},\"headline\":\"ModuleInitializer Attribute in C#\",\"datePublished\":\"2023-08-09T06:00:15+00:00\",\"dateModified\":\"2023-08-09T20:52:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/\"},\"wordCount\":859,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"keywords\":[\".NET CORE\",\"Attribute\",\"C#\",\"Dependency Injection\",\"ModuleInitializer\"],\"articleSection\":[\"C#\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/\",\"url\":\"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/\",\"name\":\"ModuleInitializer Attribute in C#\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"datePublished\":\"2023-08-09T06:00:15+00:00\",\"dateModified\":\"2023-08-09T20:52:32+00:00\",\"description\":\"In this article, we discuss the overlooked ModuleInitializer attribute in C# and showcase its use in a class library.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"width\":1100,\"height\":620,\"caption\":\"C# Development\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ModuleInitializer Attribute in C#\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\",\"name\":\"Code Maze\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"caption\":\"Code Maze\"},\"description\":\"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/company\/codemaze\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/codemazecontributor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ModuleInitializer Attribute in C#","description":"In this article, we discuss the overlooked ModuleInitializer attribute in C# and showcase its use in a class library.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/","og_locale":"en_US","og_type":"article","og_title":"ModuleInitializer Attribute in C#","og_description":"In this article, we discuss the overlooked ModuleInitializer attribute in C# and showcase its use in a class library.","og_url":"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/","og_site_name":"Code Maze","article_published_time":"2023-08-09T06:00:15+00:00","article_modified_time":"2023-08-09T20:52:32+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","type":"image\/png"}],"author":"Code Maze","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Code Maze","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/"},"author":{"name":"Code Maze","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04"},"headline":"ModuleInitializer Attribute in C#","datePublished":"2023-08-09T06:00:15+00:00","dateModified":"2023-08-09T20:52:32+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/"},"wordCount":859,"commentCount":2,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","keywords":[".NET CORE","Attribute","C#","Dependency Injection","ModuleInitializer"],"articleSection":["C#"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/","url":"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/","name":"ModuleInitializer Attribute in C#","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","datePublished":"2023-08-09T06:00:15+00:00","dateModified":"2023-08-09T20:52:32+00:00","description":"In this article, we discuss the overlooked ModuleInitializer attribute in C# and showcase its use in a class library.","breadcrumb":{"@id":"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","width":1100,"height":620,"caption":"C# Development"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/csharp-moduleinitializer-attribute\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"ModuleInitializer Attribute in C#"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04","name":"Code Maze","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","caption":"Code Maze"},"description":"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.","sameAs":["https:\/\/www.linkedin.com\/company\/codemaze\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/codemazecontributor\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/94749","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=94749"}],"version-history":[{"count":4,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/94749\/revisions"}],"predecessor-version":[{"id":94812,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/94749\/revisions\/94812"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62189"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=94749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=94749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=94749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}