{"id":4005,"date":"2017-09-08T11:51:32","date_gmt":"2017-09-08T18:51:32","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=4005"},"modified":"2025-06-13T19:40:26","modified_gmt":"2025-06-14T02:40:26","slug":"dependency-injection-aspnet-couchbase","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/","title":{"rendered":"Dependency Injection with ASP.NET Core and Couchbase"},"content":{"rendered":"<div class=\"paragraph\">\n<p>Dependency Injection is a design pattern that makes coding easier. It saves you the hassle of instantiating objects with complex dependencies, and it makes it easier for you to write tests. With the <a href=\"https:\/\/github.com\/couchbaselabs\/Couchbase.Extensions\/blob\/master\/docs\/dependency-injection.md\">Couchbase.Extensions.DependencyInjection library (GitHub)<\/a>, you can use Couchbase clusters and buckets within the ASP.NET Core dependency injection framework.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>In my last blog post on <a href=\"https:\/\/www.couchbase.com\/blog\/distributed-caching-aspnet-couchbase\/\">distributed caching with ASP.NET<\/a>, I mentioned the DependencyInjection library. Dependency injection will be explored in-depth in this post. Feel free to follow along with the code samples I\u2019ve created, available on <a href=\"https:\/\/github.com\/couchbaselabs\/blog-source-code\/tree\/master\/Groves\/078AspNetCoreDependencyInjection\/src\/CouchbaseDIExample\">GitHub<\/a>.<\/p>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_basic_setup_of_couchbase\">Basic setup of Couchbase<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>First, you\u2019ll need a Couchbase Server cluster running. You can:<\/p>\n<\/div>\n<div class=\"ulist\">\n<ul>\n<li>Install it <a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/5.0\/install\/install-intro.html\">on-premise<\/a><\/li>\n<li>Run in a container <a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/current\/getting-started\/do-a-quick-install.html\">with Docker<\/a><\/li>\n<li>Use a cloud service like <a href=\"https:\/\/azuremarketplace.microsoft.com\/en-us\/marketplace\/apps\/couchbase.couchbase-enterprise\">Azure<\/a><\/li>\n<\/ul>\n<\/div>\n<div class=\"paragraph\">\n<p>Next, you\u2019ll need to <a href=\"https:\/\/docs.couchbase.com\/server\/current\/manage\/manage-buckets\/create-bucket.html\">create a bucket<\/a> in Couchbase. This can be the &#8220;travel-sample&#8221; bucket that comes with Couchbase, or a bucket that you create yourself.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p><em>If you are using Couchbase Server 5.0, you\u2019ll also need to create a user. Give that user Cluster Admin permission, and give it the same name as the bucket, just to keep things simple if you are following along.<\/em><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_dependency_injection_with_couchbase_extensions\">Dependency Injection with Couchbase.Extensions<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>The <a href=\"https:\/\/github.com\/couchbaselabs\/Couchbase.Extensions\">Couchbase.Extensions (GitHub)<\/a> project aims to make working with Couchbase Server and ASP.NET Core simpler. Dependency Injection is just one of these extensions.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>You can add it to your ASP.NET Core project with NuGet:<\/p>\n<\/div>\n<div class=\"ulist\">\n<ul>\n<li>By using Package Manager: <code>Install-Package Couchbase.Extensions.DependencyInjection -Version 1.0.2<\/code><\/li>\n<li>With the NuGet UI<\/li>\n<li>Use the .NET command line: <code>dotnet add package Couchbase.Extensions.DependencyInjection --version 1.0.2<\/code><\/li>\n<\/ul>\n<\/div>\n<div class=\"paragraph\">\n<p><em>(Version 1.0.2 is the latest version at the time of writing).<\/em><\/p>\n<\/div>\n<div class=\"paragraph\">\n<p><span class=\"image\"><img decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2017\/09\/07801-nuget-couchbase-extension-dependency-injection.png\" alt=\"Couchbase extension for dependency injection on NuGet\" \/><\/span><\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>Next, you\u2019ll need to make changes to your <code>Startup<\/code> class in <code>Startup.cs<\/code>.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>In the blog post on caching, I hard-coded the configuration:<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-C#\">services.AddCouchbase(client =&gt;\r\n{\r\n    client.Servers = new List&lt;Uri&gt; { new Uri(\"https:\/\/localhost:8091\")};\r\n    client.UseSsl = false;\r\n});<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>This is fine for demos and blog posts, but you\u2019ll likely want to use a configuration file for a production project.<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-C#\">services.AddCouchbase(Configuration.GetSection(\"Couchbase\"));<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>Assuming you\u2019re using the default <code>appsettings.json<\/code>, update that file to add a Couchbase section:<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-JavaScript\">\"Couchbase\" : {\r\n  \"Servers\": [\r\n    \"https:\/\/localhost:8091\"\r\n  ],\r\n  \"UseSsl\": false\r\n}<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>By making a &#8220;Couchbase&#8221; section, the dependency injection module will read right from the appsettings.json text file.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_constructor_injection\">Constructor Injection<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>After dependency injection is setup, you can start injecting useful objects into your classes. You might inject them into Controllers, services, or repositories.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>Here\u2019s an example of injecting into <code>HomeController<\/code>:<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-C#\">public class HomeController : Controller\r\n{\r\n    private readonly IBucket _bucket;\r\n\r\n    public HomeController(IBucketProvider bucketProvider)\r\n    {\r\n        _bucket = bucketProvider.GetBucket(\"travel-sample\", \"password\");\r\n    }\r\n\r\n    \/\/ ... snip ...\r\n}<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>Next, let\u2019s do a simple <code>Get<\/code> operation on a well-known document in &#8220;travel-sample&#8221;. This token usage of the Couchbase .NET SDK will show dependency injection in action. I\u2019ll make a change to the generated <code>About<\/code> action method. In that method, it will retrieve a route document and write out the equipment number.<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-C#\">public IActionResult About()\r\n{\r\n    \/\/ get the route document for Columbus to Chicago (United)\r\n    var route = _bucket.Get&lt;dynamic&gt;(\"route_56027\").Value;\r\n\r\n    \/\/ display the equipment number of the route\r\n    ViewData[\"Message\"] = \"CMH to ORD - \" + route.equipment;\r\n\r\n    return View();\r\n}<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>And the result is:<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p><span class=\"image\"><img decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2017\/09\/07802-travel-sample-result.png\" alt=\"Travel sample output of a single route\" \/><\/span><\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>Success! Dependency injection worked, and we\u2019re ready to use a Couchbase bucket.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p><em>If you aren\u2019t using &#8220;travel-sample&#8221;, use a key from your own bucket.<\/em><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_named_buckets\">Named buckets<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>You can use dependency injection for a single bucket instead of having to specify the name each time.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>Start by creating an interface that implements <code>INamedBucketProvider<\/code>. Leave it empty. Here\u2019s an example:<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-C#\">public interface ITravelSampleBucketProvider : INamedBucketProvider\r\n{\r\n    \/\/ nothing goes in here!\r\n}<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>Then, back in Startup.cs, map this interface to a bucket using <code>AddCouchbaseBucket<\/code>:<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-C#\">services\r\n    .AddCouchbase(Configuration.GetSection(\"Couchbase\"))\r\n    .AddCouchbaseBucket&lt;ITravelSampleBucketProvider&gt;(\"travel-sample\", \"password\");<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>Now, the <code>ITravelSampleBucketProvider<\/code> gets injected instead of the more general provider.<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-C#\">public HomeController(ITravelSampleBucketProvider travelBucketProvider)\r\n{\r\n    _bucket = travelBucketProvider.GetBucket();\r\n}<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_more_complex_dependency_injection\">More complex dependency injection<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>Until this point, we\u2019ve only used dependency injection on Controllers. Dependency injection starts to pay dividends with more complex, deeper object graphs.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>As an example, imagine a service class that uses a Couchbase bucket, but also uses an email service.<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-C#\">public class ComplexService : IComplexService\r\n{\r\n    private readonly IBucket _bucket;\r\n    private readonly IEmailService _email;\r\n\r\n    public ComplexService(ITravelSampleBucketProvider bucketProvider, IEmailService emailService)\r\n    {\r\n        _bucket = bucketProvider.GetBucket();\r\n        _email = emailService;\r\n    }\r\n\r\n    public void ApproveApplication(string emailAddress)\r\n    {\r\n        _bucket.Upsert(emailAddress, new {emailAddress, approved = true});\r\n        _email.SendEmail(emailAddress, \"Approved\", \"Your application has been approved!\");\r\n    }\r\n}<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>Next, let\u2019s use this service in a controller (aka making it a dependency). But notice that the controller is not directly using either the bucket or the email service.<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-C#\">public class ApproveController : Controller\r\n{\r\n    private readonly IComplexService _svc;\r\n\r\n    public ApproveController(IComplexService svc)\r\n    {\r\n        _svc = svc;\r\n    }\r\n\r\n    public IActionResult Index()\r\n    {\r\n        var fakeEmailAddress = Faker.Internet.Email();\r\n        _svc.ApproveApplication(fakeEmailAddress);\r\n        ViewData[\"Message\"] = \"Approved '\" + fakeEmailAddress + \"'\";\r\n        return View();\r\n    }\r\n}<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>If I were to instantiate <code>ComplexService<\/code> manually, I would have to instantiate at least two other objects. It would look something like: <code>new ComplexService(new BucketProvider(), new MyEmailService()<\/code>. That\u2019s a lot that I have to keep track of, and if any dependencies change, it\u2019s a lot of manual maintenance.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>Instead, I can have ASP.NET Core use dependency injection to do all this for me. Back in <code>Startup<\/code>:<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-C#\">services.AddTransient&lt;IEmailService, MyEmailService&gt;();\r\nservices.AddTransient&lt;IComplexService, ComplexService&gt;();<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>Now, ASP.NET Core knows how to instantiate:<\/p>\n<\/div>\n<div class=\"ulist\">\n<ul>\n<li><code>ITravelSampleBucketProvider<\/code>, thanks to Couchbase.Extensions.DependencyInjection<\/li>\n<li><code>IEmailService<\/code> &#8211; I told it to use <code>MyEmailService<\/code><\/li>\n<li><code>IComplexService<\/code> &#8211; I told it to use <code>ComplexService<\/code><\/li>\n<\/ul>\n<\/div>\n<div class=\"paragraph\">\n<p>Finally, when <code>ApproveController<\/code> is instantiated, ASP.NET Core will know how to do it. It will create <code>ComplexService<\/code> by instantiating <code>MyEmailService<\/code> and <code>ComplexService<\/code>. It will inject <code>ComplexService<\/code> automatically into `ApproveController\u2019s constructor. The end result:<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p><span class=\"image\"><img decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2017\/09\/07803-complex-service-in-action.png\" alt=\"Complex service in action using dependency injection\" \/><\/span><\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>For the complete example, be sure to check out the <a href=\"https:\/\/github.com\/couchbaselabs\/blog-source-code\/tree\/master\/Groves\/078AspNetCoreDependencyInjection\/src\/CouchbaseDIExample\">source code that accompanies this blog post on GitHub<\/a>.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_cleaning_up\">Cleaning up<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>Don\u2019t forget to clean up after yourself. When the ASP.NET Core application is stops, release any resources that the Couchbase .NET SDK is using. In the <code>Configure<\/code> method in Startup, add a parameter of type <code>IApplicationLifetime<\/code>:<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-C#\">public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime applicationLifetime)<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>Within that <code>Configure<\/code> method, setup an <code>ApplicationStopped<\/code> event:<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-C#\">applicationLifetime.ApplicationStopped.Register(() =&gt;\r\n{\r\n    app.ApplicationServices.GetRequiredService&lt;ICouchbaseLifetimeService&gt;().Close();\r\n});<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_summary\">Summary<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>Dependency injection is a rich subject. Entire books have been written about it and its benefits to your application. This blog post just scratched the surface and didn\u2019t even cover the testability benefits.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>Couchbase.Extensions.DependencyInjection makes it easier to inject Couchbase into ASP.NET Core.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>If you have questions or comments, make sure to check out the <a href=\"https:\/\/github.com\/couchbaselabs\/Couchbase.Extensions\/blob\/master\/docs\/dependency-injection.md\">GitHub repository<\/a> or the <a href=\"https:\/\/www.couchbase.com\/forums\/c\/net-sdk\/\">Couchbase .NET SDK forums<\/a>.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>And please reach out to me with questions by leaving a comment below or finding me on <a href=\"https:\/\/twitter.com\/mgroves\">Twitter @mgroves<\/a>.<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Dependency Injection is a design pattern that makes coding easier. It saves you the hassle of instantiating objects with complex dependencies, and it makes it easier for you to write tests. With the Couchbase.Extensions.DependencyInjection library (GitHub), you can use Couchbase [&hellip;]<\/p>\n","protected":false},"author":71,"featured_media":4006,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1811,1814,10126,1815,1816],"tags":[2052],"ppma_author":[8937],"class_list":["post-4005","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","category-application-design","category-asp-dotnet","category-best-practices-and-tutorials","category-couchbase-server","tag-extensions"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.7.1 (Yoast SEO v25.7) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Dependency Injection Framework with ASP.NET Core + Couchbase<\/title>\n<meta name=\"description\" content=\"In this Couchbase post, the dependency injection framework will be explored in-depth. Feel free to follow along with the code samples available on GitHub.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Dependency Injection with ASP.NET Core and Couchbase\" \/>\n<meta property=\"og:description\" content=\"In this Couchbase post, the dependency injection framework will be explored in-depth. Feel free to follow along with the code samples available on GitHub.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2017-09-08T18:51:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T02:40:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/078-hero-injection.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"532\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Matthew Groves\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@mgroves\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Matthew Groves\" \/>\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\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/\"},\"author\":{\"name\":\"Matthew Groves\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58\"},\"headline\":\"Dependency Injection with ASP.NET Core and Couchbase\",\"datePublished\":\"2017-09-08T18:51:32+00:00\",\"dateModified\":\"2025-06-14T02:40:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/\"},\"wordCount\":849,\"commentCount\":12,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/078-hero-injection.jpg\",\"keywords\":[\"extensions\"],\"articleSection\":[\".NET\",\"Application Design\",\"ASP.NET\",\"Best Practices and Tutorials\",\"Couchbase Server\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/\",\"name\":\"Dependency Injection Framework with ASP.NET Core + Couchbase\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/078-hero-injection.jpg\",\"datePublished\":\"2017-09-08T18:51:32+00:00\",\"dateModified\":\"2025-06-14T02:40:26+00:00\",\"description\":\"In this Couchbase post, the dependency injection framework will be explored in-depth. Feel free to follow along with the code samples available on GitHub.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/078-hero-injection.jpg\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/078-hero-injection.jpg\",\"width\":800,\"height\":532,\"caption\":\"Dependency injection\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Dependency Injection with ASP.NET Core and Couchbase\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58\",\"name\":\"Matthew Groves\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/ba51e6aacc53995c323a634e4502ef54\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g\",\"caption\":\"Matthew Groves\"},\"description\":\"Matthew D. Groves is a guy who loves to code. It doesn't matter if it's C#, jQuery, or PHP: he'll submit pull requests for anything. He has been coding professionally ever since he wrote a QuickBASIC point-of-sale app for his parent's pizza shop back in the 90s. He currently works as a Senior Product Marketing Manager for Couchbase. His free time is spent with his family, watching the Reds, and getting involved in the developer community. He is the author of AOP in .NET, Pro Microservices in .NET, a Pluralsight author, and a Microsoft MVP.\",\"sameAs\":[\"https:\/\/crosscuttingconcerns.com\",\"https:\/\/x.com\/mgroves\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/matthew-groves\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Dependency Injection Framework with ASP.NET Core + Couchbase","description":"In this Couchbase post, the dependency injection framework will be explored in-depth. Feel free to follow along with the code samples available on GitHub.","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:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/","og_locale":"en_US","og_type":"article","og_title":"Dependency Injection with ASP.NET Core and Couchbase","og_description":"In this Couchbase post, the dependency injection framework will be explored in-depth. Feel free to follow along with the code samples available on GitHub.","og_url":"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/","og_site_name":"The Couchbase Blog","article_published_time":"2017-09-08T18:51:32+00:00","article_modified_time":"2025-06-14T02:40:26+00:00","og_image":[{"width":800,"height":532,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/078-hero-injection.jpg","type":"image\/jpeg"}],"author":"Matthew Groves","twitter_card":"summary_large_image","twitter_creator":"@mgroves","twitter_misc":{"Written by":"Matthew Groves","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/"},"author":{"name":"Matthew Groves","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58"},"headline":"Dependency Injection with ASP.NET Core and Couchbase","datePublished":"2017-09-08T18:51:32+00:00","dateModified":"2025-06-14T02:40:26+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/"},"wordCount":849,"commentCount":12,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/078-hero-injection.jpg","keywords":["extensions"],"articleSection":[".NET","Application Design","ASP.NET","Best Practices and Tutorials","Couchbase Server"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/","url":"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/","name":"Dependency Injection Framework with ASP.NET Core + Couchbase","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/078-hero-injection.jpg","datePublished":"2017-09-08T18:51:32+00:00","dateModified":"2025-06-14T02:40:26+00:00","description":"In this Couchbase post, the dependency injection framework will be explored in-depth. Feel free to follow along with the code samples available on GitHub.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/078-hero-injection.jpg","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/078-hero-injection.jpg","width":800,"height":532,"caption":"Dependency injection"},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/dependency-injection-aspnet-couchbase\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Dependency Injection with ASP.NET Core and Couchbase"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58","name":"Matthew Groves","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/ba51e6aacc53995c323a634e4502ef54","url":"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g","caption":"Matthew Groves"},"description":"Matthew D. Groves is a guy who loves to code. It doesn't matter if it's C#, jQuery, or PHP: he'll submit pull requests for anything. He has been coding professionally ever since he wrote a QuickBASIC point-of-sale app for his parent's pizza shop back in the 90s. He currently works as a Senior Product Marketing Manager for Couchbase. His free time is spent with his family, watching the Reds, and getting involved in the developer community. He is the author of AOP in .NET, Pro Microservices in .NET, a Pluralsight author, and a Microsoft MVP.","sameAs":["https:\/\/crosscuttingconcerns.com","https:\/\/x.com\/mgroves"],"url":"https:\/\/www.couchbase.com\/blog\/author\/matthew-groves\/"}]}},"authors":[{"term_id":8937,"user_id":71,"is_guest":0,"slug":"matthew-groves","display_name":"Matthew Groves","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g","author_category":"","last_name":"Groves","first_name":"Matthew","job_title":"","user_url":"https:\/\/crosscuttingconcerns.com","description":"Matthew D. Groves is a guy who loves to code.  It doesn't matter if it's C#, jQuery, or PHP: he'll submit pull requests for anything.  He has been coding professionally ever since he wrote a QuickBASIC point-of-sale app for his parent's pizza shop back in the 90s.  He currently works as a Senior Product Marketing Manager for Couchbase. His free time is spent with his family, watching the Reds, and getting involved in the developer community.  He is the author of AOP in .NET, Pro Microservices in .NET, a Pluralsight author, and a Microsoft MVP."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/4005","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/71"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=4005"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/4005\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/4006"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=4005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=4005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=4005"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=4005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}