{"id":70224,"date":"2022-07-04T09:06:09","date_gmt":"2022-07-04T07:06:09","guid":{"rendered":"https:\/\/drafts.code-maze.com\/?p=70224"},"modified":"2022-07-04T09:06:09","modified_gmt":"2022-07-04T07:06:09","slug":"aspnetcore-resolve-instances-with-dependency-injection","status":"publish","type":"post","link":"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/","title":{"rendered":"How to Resolve Instances With ASP.NET Core DI"},"content":{"rendered":"<p>In ASP.NET Core dependency injection, we usually register injectable dependencies at the start of our program. We can then resolve these dependencies (services) much later once when we need them. Sometimes, however, we may need to resolve those dependencies even before building our app. This happens especially when we need to initialize something at startup. This could range from a simple database for storage to a set of SCADA-controlled devices.<\/p>\n<p>If you are new to dependency injection, you should definitely read our article on <a href=\"https:\/\/code-maze.com\/dependency-injection-aspnet\/\" target=\"_blank\" rel=\"noopener\">Dependency Injection<\/a>, and come back before we start with this one.<\/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\/aspnetcore-features\/ResolvingDependencyInjection\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>Let&#8217;s get started.<\/p>\n<h2>Injecting Dependencies<\/h2>\n<p>In this article, we&#8217;ll be dealing with a simple yet important common application of dependency injection; Globalization and Localization.<\/p>\n<p>With globalization, we add support for input, display, and output of a defined set of language scripts that relate to various geographic areas and cultures. We adapt a globalized app&#8217;s content to a specific language or culture in localization. This could be based on the users&#8217; settings or requests.<\/p>\n<p>To implement localization in .NET, we inject the localization service into our application builder&#8217;s services in the <code>Program.cs<\/code> file, and point it to a\u00a0<code>Resources<\/code> directory where we&#8217;ll put all our language resources:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">builder.Services.AddLocalization();<\/code><\/p>\n<p>Now, we want to be able to provide localized error messages from our model binders whenever our app receives an incorrect model. To accomplish this, we need to set the accessor messages on the <code>ModelBindingMessageProvider<\/code> for our controller.\u00a0<\/p>\n<p>Let&#8217;s create a Resources folder where we will store all our language resources. In this folder, let&#8217;s create a <code>SharedResource<\/code> class and two resource files with the same name for English (en) and Japanese (ja).<\/p>\n<h3>Different Initialization Phases in Program Class<\/h3>\n<p>In order to set up localized accessor messages for model binding, we need to invoke our localization service within our Controller service&#8217;s configuration options. An ASP.NET Core Program has two distinct initialization phases:<\/p>\n<p>The <code>Add<\/code>\u00a0phase, <strong>where we add registrations to the container builder&#8217;s<\/strong> <code>IServiceCollection<\/code>.<\/p>\n<p>The <code>Use<\/code> phase, <strong>where we express how we want to use the previously registered services<\/strong>. During the <code>Use<\/code> phase, .NET turns the <code>IServiceCollection<\/code> into an <code>IServiceProvider<\/code> and we can then inject those services into the various methods.<\/p>\n<p>Let&#8217;s take a look at this in an illustration:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/06\/build_services-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-72038\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/06\/build_services-1.png\" alt=\"Program class two phases for registering services and pipeline\" width=\"749\" height=\"458\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/06\/build_services-1.png 749w, https:\/\/code-maze.com\/wp-content\/uploads\/2022\/06\/build_services-1-300x183.png 300w\" sizes=\"auto, (max-width: 749px) 100vw, 749px\" \/><\/a><\/p>\n<p>As we can see from our code snippet, we have only just declared our services and have not yet built the app. <strong>Therefore, we do not yet have a tangible instance of any service.<\/strong> This is where we encounter our challenge.<\/p>\n<p>How do we invoke a service that we have only declared but not yet built an instance of?<\/p>\n<h2>Manually Resolving Dependencies<\/h2>\n<p>A common but technically wrong approach would be to build the service provider at that early stage:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">builder.Services.AddLocalization();\r\nbuilder.Services.AddControllers(options =&gt;\r\n{\r\n    var localizerFactory = builder.Services.BuildServiceProvider().GetService&lt;IStringLocalizerFactory&gt;();\r\n    var localizer = localizerFactory.Create(typeof(SharedResource));\r\n    options.ModelBindingMessageProvider.SetValueIsInvalidAccessor((x) =&gt; localizer[\"The value '{0}' is invalid.\", x]);\r\n});<\/pre>\n<p>In our snippet, we&#8217;re declaring the localization service and making our app build a service provider so that we can retrieve an instance of <code>IStringLocalizerFactory<\/code>. Using the localizer factory, we then set custom binding messages. <strong>The trouble with this approach is that although we built the service provider here, the app must still build another one at the<\/strong> <code>app = builder.Build()<\/code> <strong>stage<\/strong>. Let&#8217;s take a look at this illustrated:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/06\/build_services_early.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-72039\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/06\/build_services_early.png\" alt=\"Wrong way to resolve instances in ASP.NET Core\" width=\"976\" height=\"458\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/06\/build_services_early.png 976w, https:\/\/code-maze.com\/wp-content\/uploads\/2022\/06\/build_services_early-300x141.png 300w, https:\/\/code-maze.com\/wp-content\/uploads\/2022\/06\/build_services_early-768x360.png 768w\" sizes=\"auto, (max-width: 976px) 100vw, 976px\" \/><\/a><\/p>\n<p>When this happens, each service provider will have its own cache of resolved instances. In the case of singleton instances, since we have two separate service providers, <strong>we will therefore end up with more than one instance.<\/strong> This violates the guarantee that there must be at most, one instance for a given singleton registration. For scoped dependencies, building in one provider and caching in the other, will result in the dependency outliving its scope, and lasting for the lifetime of the application.<\/p>\n<p>Now, let&#8217;s see a better way to resolve this.<\/p>\n<h2>Resolving Dependencies With Static Classes<\/h2>\n<p>A neat way to resolve this issue is by creating a static class or a class with static properties which we can then reference from any point in our program.<\/p>\n<p>Let&#8217;s create the class file <code>LocalizerManager.cs<\/code> for our project. It contains a static property of type <code>IStringLocalizer<\/code> called <code>localizer<\/code> and a static action <code>SetLocalizationOptions<\/code> which accepts an <code>MvcOptions<\/code> input:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static class LocalizerManager\r\n{\r\n    private static IStringLocalizer? _localizer;\r\n    \r\n    public static void SetLocalizationOptions(MvcOptions options)\r\n    {\r\n        options.ModelBindingMessageProvider\r\n             .SetMissingRequestBodyRequiredValueAccessor(() =&gt; localizer.GetString(\"MissingRequestBodyRequiredValue\"));\r\n    }\r\n\r\n    public static void SetLocalizer(IStringLocalizer localizer)\r\n    {\r\n        _localizer = localizer;\r\n    }\r\n}<\/pre>\n<p>In our static method, we can now set the accessors using the static localizer property available to us within the class. Note that we made our <code>IStringLocalizer<\/code> nullable because we are not initializing it in the constructor. Instead, we will assign it a value back in our program file.<\/p>\n<p>Now, let&#8217;s update our <code>Program<\/code> file to assign the localizer and call our static method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">builder.Services.AddControllers(options =&gt;\r\n{\r\n    LocalizerManager.SetLocalizationOptions(options);\r\n});\r\n\r\n\/*\r\n   Other services\r\n*\/\r\n\r\nvar app = builder.Build();\r\n\r\n\r\nusing (var serviceScope = app.Services.CreateScope())\r\n{\r\n    var services = serviceScope.ServiceProvider;\r\n\r\n    var localizer = services.GetRequiredService&lt;IStringLocalizerFactory&gt;()\r\n                        .Create(typeof(SharedResource));\r\n\r\n    LocalizerManager.SetLocalizer(localizer);\r\n}<\/pre>\n<p>In the <code>AddControllers<\/code> method, we are calling the static method we created and passing in the options object to it.<\/p>\n<p>Since the input to the <code>AddControllers<\/code> method is a delegate, we know that it does not execute immediately after it is declared. Instead, execution continues through the <code>build<\/code> and <code>run<\/code> phases before hitting the delegate. Therefore, we have leeway to assign the localizer after safely building the app, which is exactly what we&#8217;ve done here. By creating a disposable service scope, we ensure that we aren&#8217;t leaving any orphaned services in our cache.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this article, we learned about the order in which .NET initializes our application&#8217;s services, and how to maintain it. We also learned about the challenges and pitfalls we face when we need to resolve a service before runtime. Dependency injection is an important part of good software architecture, and when we do it right, we can avoid many pitfalls.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In ASP.NET Core dependency injection, we usually register injectable dependencies at the start of our program. We can then resolve these dependencies (services) much later once when we need them. Sometimes, however, we may need to resolve those dependencies even before building our app. This happens especially when we need to initialize something at startup. [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":62187,"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,504],"tags":[79,1332,1331,1330],"class_list":["post-70224","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-csharp","category-design-pattern","tag-asp-net-core","tag-resolve-instances-with-asp-net-core","tag-resolving-dependencies","tag-resolving-instances","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>How to Resolve Instances With ASP.NET Core DI - Code Maze<\/title>\n<meta name=\"description\" content=\"Sometimes, we may need to resolve dependencies before building our app. We encounter a challenge here, and resolve it in this article.\" \/>\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\/aspnetcore-resolve-instances-with-dependency-injection\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Resolve Instances With ASP.NET Core DI - Code Maze\" \/>\n<meta property=\"og:description\" content=\"Sometimes, we may need to resolve dependencies before building our app. We encounter a challenge here, and resolve it in this article.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-04T07:06:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.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\/aspnetcore-resolve-instances-with-dependency-injection\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/\"},\"author\":{\"name\":\"Code Maze\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\"},\"headline\":\"How to Resolve Instances With ASP.NET Core DI\",\"datePublished\":\"2022-07-04T07:06:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/\"},\"wordCount\":910,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png\",\"keywords\":[\"asp.net core\",\"Resolve Instances With ASP.NET Core\",\"Resolving Dependencies\",\"Resolving Instances\"],\"articleSection\":[\"C#\",\"Design Pattern\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/\",\"url\":\"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/\",\"name\":\"How to Resolve Instances With ASP.NET Core DI - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png\",\"datePublished\":\"2022-07-04T07:06:09+00:00\",\"description\":\"Sometimes, we may need to resolve dependencies before building our app. We encounter a challenge here, and resolve it in this article.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png\",\"width\":1100,\"height\":620,\"caption\":\"ASP.NET Core\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Resolve Instances With ASP.NET Core DI\"}]},{\"@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":"How to Resolve Instances With ASP.NET Core DI - Code Maze","description":"Sometimes, we may need to resolve dependencies before building our app. We encounter a challenge here, and resolve it in this article.","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\/aspnetcore-resolve-instances-with-dependency-injection\/","og_locale":"en_US","og_type":"article","og_title":"How to Resolve Instances With ASP.NET Core DI - Code Maze","og_description":"Sometimes, we may need to resolve dependencies before building our app. We encounter a challenge here, and resolve it in this article.","og_url":"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/","og_site_name":"Code Maze","article_published_time":"2022-07-04T07:06:09+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.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\/aspnetcore-resolve-instances-with-dependency-injection\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/"},"author":{"name":"Code Maze","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04"},"headline":"How to Resolve Instances With ASP.NET Core DI","datePublished":"2022-07-04T07:06:09+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/"},"wordCount":910,"commentCount":0,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png","keywords":["asp.net core","Resolve Instances With ASP.NET Core","Resolving Dependencies","Resolving Instances"],"articleSection":["C#","Design Pattern"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/","url":"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/","name":"How to Resolve Instances With ASP.NET Core DI - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png","datePublished":"2022-07-04T07:06:09+00:00","description":"Sometimes, we may need to resolve dependencies before building our app. We encounter a challenge here, and resolve it in this article.","breadcrumb":{"@id":"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png","width":1100,"height":620,"caption":"ASP.NET Core"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/aspnetcore-resolve-instances-with-dependency-injection\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"How to Resolve Instances With ASP.NET Core DI"}]},{"@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\/70224","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=70224"}],"version-history":[{"count":2,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/70224\/revisions"}],"predecessor-version":[{"id":72078,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/70224\/revisions\/72078"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62187"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=70224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=70224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=70224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}