﻿
{"id":14979,"date":"2020-04-06T00:41:41","date_gmt":"2020-04-06T00:41:41","guid":{"rendered":"https:\/\/www.gencayyildiz.com\/blog\/?p=14979"},"modified":"2020-04-06T00:41:41","modified_gmt":"2020-04-06T00:41:41","slug":"asp-net-core-web-api-uygulamalarinda-miniprofiler-kullanimi","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/asp-net-core-web-api-uygulamalarinda-miniprofiler-kullanimi\/","title":{"rendered":"Asp.NET Core Web API Uygulamalar\u0131nda MiniProfiler Kullan\u0131m\u0131"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>Bu i\u00e7eri\u011fimizde, Asp.NET Core Web API uygulamalar\u0131n\u0131n performans\u0131n\u0131 de\u011ferlendirmek i\u00e7in gerekli profili olu\u015fturmam\u0131z\u0131 sa\u011flayan Mini Profiler aray\u00fcz\u00fc \u00fczerine konu\u015fuyor olaca\u011f\u0131z.<\/p>\n<h3>Ba\u015flarken<\/h3>\n<p>MiniProfiler&#8217;\u0131 kullanabilmek i\u00e7in \u00f6ncelik olarak hali haz\u0131r bir Asp.NET Core Web API projesine <a href=\"https:\/\/www.nuget.org\/packages\/MiniProfiler.AspNetCore.Mvc\/\" rel=\"noopener noreferrer\" target=\"_blank\">MiniProfiler.AspNetCore.Mvc<\/a> ve <a href=\"https:\/\/www.nuget.org\/packages\/MiniProfiler.EntityFrameworkCore\" rel=\"noopener noreferrer\" target=\"_blank\">MiniProfiler.EntityFrameworkCore<\/a> k\u00fct\u00fcphanelerini y\u00fcklemeniz gerekmektedir.<\/p>\n<p><code><strong>dotnet add package MiniProfiler.AspNetCore.Mvc --version 4.1.0<\/strong><\/code><br \/>\n<code><strong>dotnet add package MiniProfiler.EntityFrameworkCore --version 4.1.0<\/strong><\/code><\/p>\n<h3>Uygulamaya Entegre Edilmesi<\/h3>\n<p>Uygulamaya MiniProfiler k\u00fct\u00fcphanelerini y\u00fckledikten sonra entegrasyon i\u015flemleri i\u00e7in &#8216;Startup.cs&#8217; dosyas\u0131nda a\u015fa\u011f\u0131daki gibi gerekli konfig\u00fcrasyonlar ger\u00e7ekle\u015ftirilmelidir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    public class Startup\r\n    {\r\n        public void ConfigureServices(IServiceCollection services)\r\n        {\r\n            services.AddMemoryCache();\r\n\r\n            services.AddMiniProfiler(options =&gt;\r\n            {\r\n                \/\/Buradaki t\u00fcm konfig\u00fcrasyonlar iste\u011fe ba\u011fl\u0131d\u0131r.\r\n                \/\/Bo\u015f b\u0131rakt\u0131\u011f\u0131n\u0131z taktirde varsay\u0131lan de\u011ferler s\u00f6z konusu olacakt\u0131r.\r\n                options.RouteBasePath = &quot;\/profiler&quot;;\r\n\r\n                \/\/60 dakikada bir depolama kontrol edilecektir.\r\n                \/\/Varsay\u0131lan de\u011feri 30 dakikad\u0131r.\r\n                (options.Storage as MemoryCacheStorage).CacheDuration = TimeSpan.FromMinutes(60);\r\n\r\n                \/\/SQL formatlay\u0131c\u0131s\u0131 kontrol edilmektedir.\r\n                \/\/Varsay\u0131lan olarak InlineFormatter'dir.\r\n                options.SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter();\r\n\r\n                \/\/Ba\u011flant\u0131 a\u00e7ma ve kapatmay\u0131 izlemeyi devre d\u0131\u015f\u0131 b\u0131rakabilirsiniz.\r\n                \/\/Varsay\u0131lan olarak izlenmektedir.(true)\r\n                options.TrackConnectionOpenClose = true;\r\n            }).AddEntityFramework(); ;\r\n            services.AddControllers();\r\n        }\r\n\r\n        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)\r\n        {\r\n            if (env.IsDevelopment())\r\n                app.UseDeveloperExceptionPage();\r\n\r\n            \/\/MiniProfiler ara katman\u0131n\u0131 ekliyoruz.\r\n            app.UseMiniProfiler();\r\n\r\n            app.UseRouting();\r\n\r\n            app.UseEndpoints(endpoints =&gt;\r\n            {\r\n                endpoints.MapControllers();\r\n            });\r\n        }\r\n    }\r\n<\/pre>\n<p>5. sat\u0131rda belirtilen &#8216;AddMemoryCache&#8217; ile uygulamaya in-memory cache eklenmektedir. MiniProfiler i\u00e7in bu mod\u00fcl zaruridir. Aksi taktirde uygulama runtime&#8217;da a\u015fa\u011f\u0131daki olas\u0131 hatay\u0131 verecektir.<\/p>\n<div style=\"text-align:center;\"><em style=\"color:red;\">Some services are not able to be constructed (Error while validating the service descriptor &#8216;ServiceType: Microsoft.Extensions.Options.IConfigureOptions`1<br \/>\n[StackExchange.Profiling.MiniProfilerOptions] Lifetime: Singleton ImplementationType: Microsoft.Extensions.DependencyInjection.MiniProfilerOptionsDefaults&#8217;: Unable to resolve service for type &#8216;Microsoft.Extensions.Caching.Memory.IMemoryCache&#8217; while attempting to activate &#8216;Microsoft.Extensions.DependencyInjection.MiniProfilerOptionsDefaults&#8217;.)&#8217;<\/em>\n<\/div>\n<p>Olas\u0131 hatan\u0131n g\u00f6rsel hali;<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131.jpg\" alt=\"Asp.NET Core Web API Uygulamalar\u0131nda MiniProfiler Kullan\u0131m\u0131\" width=\"436\" height=\"241\" class=\"aligncenter size-full wp-image-14992\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131.jpg 436w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-300x166.jpg 300w\" sizes=\"auto, (max-width: 436px) 100vw, 436px\" \/><\/a><\/p>\n<p>Bu i\u015flemler neticesinde MiniProfiler entegrasyonu tamamlanm\u0131\u015ft\u0131r. Art\u0131k 11. sat\u0131rdaki &#8220;RouteBasePath&#8221; propertyesine verilen &#8216;\/profiler&#8217; de\u011ferinin uzant\u0131s\u0131 olarak; uygulamaya yap\u0131lan t\u00fcm isteklerin listesine <span style=\"color:red;\">&#8216;\/profiler\/results-index&#8217;<\/span> adresinden, ge\u00e7erli olan son iste\u011fe ise <span style=\"color:red;\">&#8216;\/profiler\/results&#8217;<\/span> adresinden eri\u015filebilmektedir. Ve t\u00fcm bu yap\u0131lan istekler <span style=\"color:red;\">&#8216;\/profiler\/results-list&#8217;<\/span> adresinden json olarak elde edilebilmektedir.<\/p>\n<h3>\u0130nceleme<\/h3>\n<p>\u015eimdi gelin \u00e7al\u0131\u015fan bir uygulamada MiniProfiler&#8217;\u0131 test edelim.<\/p>\n<p>Yap\u0131lan t\u00fcm istekleri g\u00f6rmek i\u00e7in &#8216;https:\/\/localhost:5001\/profiler\/results-index&#8217; adresini inceleyelim.<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-1.jpg\" alt=\"Asp.NET Core Web API Uygulamalar\u0131nda MiniProfiler Kullan\u0131m\u0131\" width=\"928\" height=\"202\" class=\"aligncenter size-full wp-image-14999\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-1.jpg 928w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-1-300x65.jpg 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-1-768x167.jpg 768w\" sizes=\"auto, (max-width: 928px) 100vw, 928px\" \/><\/a><\/p>\n<p>Yap\u0131lan istekleri hususi olarak inceleyelim;<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-2.jpg\" alt=\"Asp.NET Core Web API Uygulamalar\u0131nda MiniProfiler Kullan\u0131m\u0131\" width=\"958\" height=\"664\" class=\"aligncenter size-full wp-image-15000\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-2.jpg 958w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-2-300x208.jpg 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-2-768x532.jpg 768w\" sizes=\"auto, (max-width: 958px) 100vw, 958px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-3.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-3.jpg\" alt=\"Asp.NET Core Web API Uygulamalar\u0131nda MiniProfiler Kullan\u0131m\u0131\" width=\"960\" height=\"725\" class=\"aligncenter size-full wp-image-15001\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-3.jpg 960w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-3-300x227.jpg 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-3-768x580.jpg 768w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/a><\/p>\n<p>G\u00f6r\u00fcld\u00fc\u011f\u00fc \u00fczere MiniProfiler, yap\u0131lan istek neticesinde iste\u011fin g\u00f6nderildi\u011fi endpoint&#8217;ten tutun arkada \u00fcretilen SQL sorgusuna kadar t\u00fcm \u00e7\u0131kt\u0131lar\u0131 g\u00f6rebilmenize ve b\u00f6ylece istek s\u00fcrecinde zaman\u0131n nerede harcand\u0131\u011f\u0131n\u0131 daha detayl\u0131 kavrayarak, varsa sorunlar\u0131 ay\u0131klaman\u0131za ve performans\u0131 do\u011fru bir \u015fekilde optimize etmenize yard\u0131mc\u0131 olmaktad\u0131r. <\/p>\n<h3>\u00d6zel Kod Profili Olu\u015fturma<\/h3>\n<p>MiniProfiler, taraf\u0131m\u0131zca \u00f6zelle\u015ftirilmi\u015f kod profili olu\u015fturmaya da imkan tan\u0131maktad\u0131r. Bunun i\u00e7in a\u015fa\u011f\u0131daki \u00f6rnek kodu inceleyiniz;<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    &#x5B;ApiController]\r\n    &#x5B;Route(&quot;api\/&#x5B;controller]&quot;)]\r\n    public class EmployeeController : ControllerBase\r\n    {\r\n        readonly NorthwindContext _northwindContext;\r\n        public EmployeeController(NorthwindContext northwindContext)\r\n        {\r\n            _northwindContext = northwindContext;\r\n        }\r\n        &#x5B;HttpPut()]\r\n        public async Task&lt;IActionResult&gt; Put(Employee employee)\r\n        {\r\n            using (MiniProfiler.Current.Step(&quot;G\u00fcncelleme Metodu&quot;))\r\n            {\r\n                bool hasData = false;\r\n                using (MiniProfiler.Current.Step(&quot;G\u00fcncellenecek personel kontrol ediliyor.&quot;))\r\n                {\r\n                    hasData = await _northwindContext.Employees.AnyAsync(_ =&gt; _.Id == employee.Id);\r\n                    if (hasData)\r\n                        using (MiniProfiler.Current.Step(&quot;Personel g\u00fcncelleniyor.&quot;))\r\n                        {\r\n                            _northwindContext.Entry(employee).State = EntityState.Modified;\r\n                            await _northwindContext.SaveChangesAsync();\r\n                        }\r\n                }\r\n            }\r\n\r\n            return NoContent();\r\n        }\r\n    }\r\n<\/pre>\n<p>Geli\u015ftirdi\u011fimiz bu custom kod profilini aya\u011fa kald\u0131r\u0131p istek g\u00f6nderdi\u011fimizde<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-4.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-4.jpg\" alt=\"Asp.NET Core Web API Uygulamalar\u0131nda MiniProfiler Kullan\u0131m\u0131\" width=\"865\" height=\"998\" class=\"aligncenter size-full wp-image-15008\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-4.jpg 865w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-4-260x300.jpg 260w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131-4-768x886.jpg 768w\" sizes=\"auto, (max-width: 865px) 100vw, 865px\" \/><\/a><br \/>\ng\u00f6r\u00fcld\u00fc\u011f\u00fc \u00fczere mevcut yap\u0131daki t\u00fcm yap\u0131lanman\u0131n detay\u0131n\u0131 g\u00f6rmemizi sa\u011flamakta ve olas\u0131 sorunlar\u0131 h\u0131zl\u0131ca belirleyip, gidermemize imkan tan\u0131maktad\u0131r.<\/p>\n<h3>Asp.NET Core MVC Uygulamalar\u0131na \u00d6zel TagHelper<\/h3>\n<p>MiniProfiler, Asp.NET Core uygulamalar\u0131na \u00f6zel bir TagHelper ile pratik bir \u015fekilde kullan\u0131labilmektedir.<br \/>\n<code style=\"color:red;\">@addTagHelper *, MiniProfiler.AspNetCore.Mvc<\/code><br \/>\nKomutunun ard\u0131ndan layout dosyas\u0131nda a\u015fa\u011f\u0131daki TagHelper&#8217;\u0131 kullanman\u0131z yeterlidir.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&lt;mini-profiler \/&gt;\r\n<\/pre>\n<p><a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/Asp.NET-Core-Web-API-Uygulamalar\u0131nda-MiniProfiler-Kullan\u0131m\u0131.gif\" alt=\"Asp.NET Core Web API Uygulamalar\u0131nda MiniProfiler Kullan\u0131m\u0131\" width=\"512\" height=\"376\" class=\"aligncenter size-full wp-image-15014\" \/><\/a><\/p>\n<p>Nihai olarak; MiniProfiler, Asp.NET Core web uygulamalar\u0131n\u0131 profillememize yard\u0131mc\u0131 olan g\u00fczel ve kullan\u0131\u015fl\u0131 bir k\u00fct\u00fcphanedir. MSSQL yan\u0131nda bir\u00e7ok farkl\u0131 veritaban\u0131 provider\u0131n\u0131 desteklemekte ve ihtiyac\u0131n\u0131za g\u00f6re \u00f6zelle\u015ftirilebilmektedir.<\/p>\n<p>\u0130lgilenenlerin faydalanmas\u0131 dile\u011fiyle&#8230;<br \/>\nSonraki yaz\u0131lar\u0131mda g\u00f6r\u00fc\u015fmek \u00fczere&#8230;<br \/>\n\u0130yi \u00e7al\u0131\u015fmalar&#8230;<\/p>\n<p>Not : \u00d6rnek uygulamay\u0131 indirmek i\u00e7in <a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/04\/MiniProfilerExample.zip\">buraya<\/a> t\u0131klay\u0131n\u0131z.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Merhaba, Bu i\u00e7eri\u011fimizde, Asp.NET Core Web API uygulamalar\u0131n\u0131n performans\u0131n\u0131 de\u011ferlendirmek i\u00e7in gerekli profili olu\u015fturmam\u0131z\u0131 sa\u011flayan Mini Profiler aray\u00fcz\u00fc \u00fczerine konu\u015fuyor olaca\u011f\u0131z. Ba\u015flarken MiniProfiler&#8217;\u0131 kullanabilmek i\u00e7in \u00f6ncelik olarak hali haz\u0131r bir Asp.NET Core Web API&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":9596,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3102],"tags":[2679,3376,3378,3377,3379],"class_list":["post-14979","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-asp-net-core","tag-asp-net-core","tag-asp-net-core-mini-profiler","tag-asp-net-core-miniprofiler","tag-mini-profiler","tag-miniprofiler"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/14979","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/comments?post=14979"}],"version-history":[{"count":30,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/14979\/revisions"}],"predecessor-version":[{"id":15016,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/14979\/revisions\/15016"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/9596"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=14979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=14979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=14979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}