{"id":8356,"date":"2020-07-08T19:43:51","date_gmt":"2020-07-08T19:43:51","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=8356"},"modified":"2020-07-09T21:40:45","modified_gmt":"2020-07-09T21:40:45","slug":"adding-imports-to-your-blazor-app","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/adding-imports-to-your-blazor-app\/","title":{"rendered":"Adding imports to your Blazor app."},"content":{"rendered":"<p>The default template&#8217;s supplied for Blazor Server and WebAssembly applications, gives you lots upfront. However, ofcourse you&#8217;re likely to want to import further functionality via the <em>@using<\/em> directive.<\/p>\n<p>For example, let&#8217;s say we want to add the following to the Counter.razor IncrementCount method (from the default template generated files)<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nDebug.WriteLine(&quot;Increment&quot;);\r\n<\/pre>\n<p>We can simply add the following to the top of the Counter.razor file<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n@using System.Diagnostics\r\n<\/pre>\n<p>Alternatively and especially useful for using code across multiple pages\/components, you can put the above code into the _Imports.razor file. Think of this as a global set of using reference, but only for @code sections, for standard C# classes we ofcourse use the using directive as usual.<\/p>\n<p><em>Note: I&#8217;ve found my current version of Visual Studio doesn&#8217;t seem to immediately recognise the updated _Imports.razor file, a build fixes that.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The default template&#8217;s supplied for Blazor Server and WebAssembly applications, gives you lots upfront. However, ofcourse you&#8217;re likely to want to import further functionality via the @using directive. For example, let&#8217;s say we want to add the following to the Counter.razor IncrementCount method (from the default template generated files) Debug.WriteLine(&quot;Increment&quot;); We can simply add the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[305],"tags":[],"class_list":["post-8356","post","type-post","status-publish","format-standard","hentry","category-blazor"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=8356"}],"version-history":[{"count":3,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8356\/revisions"}],"predecessor-version":[{"id":8394,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8356\/revisions\/8394"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=8356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=8356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=8356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}