<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nayanajith Pilapitiya on Medium]]></title>
        <description><![CDATA[Stories by Nayanajith Pilapitiya on Medium]]></description>
        <link>https://medium.com/@nayanajith89?source=rss-9c2e2aa621ef------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0-qjOr6ptiolXAk4pKj73g.png</url>
            <title>Stories by Nayanajith Pilapitiya on Medium</title>
            <link>https://medium.com/@nayanajith89?source=rss-9c2e2aa621ef------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 06:20:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nayanajith89/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Attribute Your Services: Unlocking the Power of Automated Registration]]></title>
            <link>https://medium.com/@nayanajith89/attribute-your-services-unlocking-the-power-of-automated-registration-f795fd4141fc?source=rss-9c2e2aa621ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/f795fd4141fc</guid>
            <category><![CDATA[custom-attributes]]></category>
            <category><![CDATA[aspnet-core-web-api]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <dc:creator><![CDATA[Nayanajith Pilapitiya]]></dc:creator>
            <pubDate>Sat, 10 Feb 2024 02:47:09 GMT</pubDate>
            <atom:updated>2024-02-10T02:47:09.601Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jKyZhe-iu2XVRA0WYxJ8CA.png" /></figure><p>Dependency injection (DI) plays a crucial role in building loosely coupled, testable, and maintainable ASP.NET Core Web APIs. However, manually registering services/repositories or any other element in Program.cs can become cumbersome as your project grows. This article explores an alternative approach using custom attributes and reflection to automate registration, enhancing scalability and maintainability. From here onwards I’ll be using services as an example but this approach can be used to any element you want to register.</p><p>Imagine an API with numerous service classes scattered across the codebase. Each service needs to be registered in Program.cs to be accessible through DI. This manual approach can lead to:</p><ul><li><strong>Repetitive Boilerplate:</strong> Duplication of registration code for similar services.</li><li><strong>Spread-Out Logic:</strong> Difficult to manage and locate service registration logic.</li><li><strong>Error-Proneness:</strong> Increased risk of typos or incorrect registrations.</li></ul><p>By automating service registration, you can gain:</p><ul><li><strong>Reduced Redundancy:</strong> Eliminate repetitive code and centralize registration.</li><li><strong>Improved Organization:</strong> Clearly define service configurations in a dedicated location.</li><li><strong>Enhanced Maintainability:</strong> Simplify code changes and make refactoring easier.</li></ul><h3>Step 01: Introduce a custom attribute</h3><p>This attribute allows you to:</p><ul><li>Specify the service interface the decorated class implements (ServiceInterface).</li><li>Set the desired lifetime (Transient, Scoped, or Singleton).</li></ul><pre>[AttributeUsage(AttributeTargets.Class)]<br>public class MyCustomAttribute: Attribute<br>{<br>    public Type ServiceInterface { get; set; }<br>    public LifetimeOfService Lifetime { get; set; } = LifetimeOfService.Scoped;<br><br>    public MyCustomAttribute(Type ServiceInterface, LifetimeOfService ServiceLifetime)<br>    {<br>        this.ServiceInterface = ServiceInterface;<br>        this.Lifetime = ServiceLifetime;<br>    }<br>}<br><br>public enum LifetimeOfService<br>{<br>    Transient = 1,<br>    Scoped = 2,<br>    Singleton = 3<br>}</pre><h3>Step 02: Decorate your Service with the Custom attribute.</h3><pre>[MyCustomAttribute(typeof(IMyService), LifetimeOfService.Scoped)]<br>public class MyService : INyService<br>{<br><br>    public AccountService()<br>    {<br><br>    }<br><br>    public async Task&lt;MyResponse&gt; DoSomething(MyRequest request)<br>    {<br>        return new MyResponse();<br>    }<br>}</pre><h3>Step 03: Use reflection to register</h3><pre>foreach (var type in curruntAssembly.GetTypes().Where(x =&gt; x.CustomAttributes.Where(y =&gt; y.AttributeType == typeof(MyCustomAttribute)).Any()))<br>{<br>    var attribute = type.GetCustomAttribute&lt;MyCustomAttribute&gt;();<br>    if (attribute != null)<br>    {<br>        var serviceInterface = attribute.ServiceInterface;<br>        var lifetime = attribute.Lifetime;<br><br>        if (serviceInterface.IsAssignableFrom(type))<br>        {<br>            if (lifetime == LifetimeOfService.Scoped)<br>                services.AddScoped(serviceInterface, type);<br><br>            if (lifetime == LifetimeOfService.Transient)<br>                services.AddTransient(serviceInterface, type);<br><br>            if (lifetime == LifetimeOfService.Singleton)<br>                services.AddSingleton(serviceInterface, type);<br>        }<br>    }<br>}</pre><p>This can be further optimized and improve. Give me your thoughts.</p><blockquote>Below code base is the one I started with initially.</blockquote><blockquote>This method does not use a custom attribute it uses a base interface and the service interfaces implements the base interface and the service class implement the service interface.</blockquote><pre>public interface IBaseService{}<br><br>public interface IMyService : IBaseService {}<br><br>public class MyService : IMyService {}</pre><blockquote>But this way it was more complicated error prone and difficult to maintain. In coming articles I’ll come with more updates on the both approaches.</blockquote><pre>foreach (System.Reflection.TypeInfo typeIntreface in curruntAssembly.GetTypes().Where(x =&gt; x.IsInterface == true).Cast&lt;TypeInfo&gt;())<br>{<br>    if (typeIntreface.ImplementedInterfaces.Any() &amp;&amp; typeIntreface.ImplementedInterfaces.Where(x =&gt; x.Name == typeof(IBaseService).Name).Any())<br>    {<br>        foreach (var typeImplementation in from TypeInfo typeInfo2 in Assembly.GetExecutingAssembly().GetTypes().Where(x =&gt; x.IsInterface == false)<br>                                           where typeInfo2.ImplementedInterfaces.Any() &amp;&amp; typeInfo2.ImplementedInterfaces.Where(x =&gt; x.Name == typeIntreface.Name).Any()<br>                                           select typeInfo2)<br>        {<br>            services.AddScoped(typeIntreface, typeImplementation);<br>        }<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f795fd4141fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IBM API connect]]></title>
            <link>https://medium.com/@nayanajith89/ibm-api-connect-326a6b38f334?source=rss-9c2e2aa621ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/326a6b38f334</guid>
            <category><![CDATA[api-gateway]]></category>
            <category><![CDATA[ibm-api-connect]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Nayanajith Pilapitiya]]></dc:creator>
            <pubDate>Thu, 03 Aug 2023 16:31:00 GMT</pubDate>
            <atom:updated>2023-08-03T16:31:00.121Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article I am going to discuss basics on IBM API connect.</p><h4>What is IBM API connect</h4><blockquote>The definition given by the IBM is “IBM API Connect is a full lifecycle API management solution that uses an intuitive experience to help consistently create, manage, secure, socialize and monetize APIs, helping power digital transformation on premises and across clouds.”</blockquote><h4>A simple use case of IBM API connect</h4><p>Assume you are an organization who are handling the entire country land registry. As an organization you are going to digitalize the data, entire process and allows other parties as banks , lawyers or any other permissioned party to develop there own application to interact with your organization information based on pre determined criteria. IBM API connect is your go to partner.</p><p>IBM API Connect work as a middle layer between the API consumers and the API producers. This allows IBM API Connect to provide a number of features that can help to improve the security, scalability, and maintainability of APIs.</p><h4>Why use IBM API Connect?</h4><p>Organizations can utilize out of the box advance security features provided by AWS to secure the endpoints with simple steps.</p><p>It make easy to create, manage, and update APIs. This helps organizations to quickly respond to changes required and adopt to business needs, demands with ease.</p><p>There are number of options that can help organizations monetize cost, performance, subscription, usage.</p><p>IBM API connect route API requests through a secure and scalable infrastructure. This helps to improve performance by minimizing latency and maximising the throughput. And also response caching and load balancing is a great advantage of using IBM API connect.</p><p>With the extended audit features it makes easy to identify vulnerabilities, helps with performance improvements, ensure compliments, and specially helps to understand the usage of the API and identify potential business and technical changes if the future.</p><h4>How to use IBM API Connect</h4><p>If you are interested in using IBM API Connect they have a 30 day free trial which can use and it does not need a credit or debit card.</p><p>Please use following URL to go to <a href="https://www.ibm.com/products/api-connect?utm_content=SRCWW&amp;p1=Search&amp;p4=43700077037569805&amp;p5=e&amp;gclid=EAIaIQobChMItLDB7_HAgAMVx5hmAh06wgC_EAAYASAAEgIlifD_BwE&amp;gclsrc=aw.ds">IBM API Connect</a></p><p>Click on the <strong>Try free </strong>button<strong> </strong>and you will be redirect to the register page of the IBM API connect.</p><p>Under <em>Products -&gt; Features </em>you can see the API Connect option. Click on the link and you will be redirect to the API connect page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ry-A1qcHApTQhg3QPyvFXA.png" /></figure><p>And in the IBM site you will be able to find the relevant documentation on the product as well. Will discuss further on another article the inside of the API connect and how can we setup one.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=326a6b38f334" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Security headers” an extra layer of security for your application.]]></title>
            <link>https://medium.com/@nayanajith89/security-headers-an-extra-layer-of-security-for-your-application-ca69f465fd4?source=rss-9c2e2aa621ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca69f465fd4</guid>
            <category><![CDATA[cyber-threat]]></category>
            <category><![CDATA[security-header]]></category>
            <category><![CDATA[application-security]]></category>
            <category><![CDATA[software-design]]></category>
            <category><![CDATA[web-app-development]]></category>
            <dc:creator><![CDATA[Nayanajith Pilapitiya]]></dc:creator>
            <pubDate>Thu, 20 Apr 2023 03:21:27 GMT</pubDate>
            <atom:updated>2023-04-20T03:21:27.768Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oT1Uadw9D4wLJU5JJKPe5A.jpeg" /></figure><p>Application security is one of the key point consider on developing an application. As developers we spent lot of time and effort to protect the applications from intruders, who are actively looking for loop holes. We follow industry best practices, do pen tests, use various tools and mechanism to protect the application.</p><p>A few approaches we use to protect our applications are</p><blockquote>Use HTTPS protocol</blockquote><blockquote>Use a SSL certificate issued by trusted party</blockquote><blockquote>Use a firewall</blockquote><blockquote>Use strong password</blockquote><p>Though we have worked really hard on on more advanced and strong security measures most of us not utilizing the full use of simplest yet effective method which is “Security Headers”.</p><h4>The following research shows how much active websites use security headers to protect the website.</h4><p>These researches are bit old but it gives us more insight on the adaptation and usage of security headers.</p><blockquote><a href="https://www.researchgate.net/publication/326280169_HTTP_security_headers_analysis_of_top_one_million_websites">Arturs Lavrenovs, F. Jesus Rubio Melon (2018) “HTTP security headers analysis of top one million websites”</a></blockquote><blockquote><a href="https://www.researchgate.net/publication/320247591_Analysis_of_the_Adoption_of_Security_Headers_in_HTTP">William J Buchanan, Scott Helme, Alan Woodward (2017)“Analysis of the Adoption of Security Headers in HTTP”</a></blockquote><h3><strong>What are Security Headers</strong></h3><p>Security headers are additional HTTP response headers that can be added to a web server’s HTTP response to provide an extra layer of security to web applications. These headers instructs web browser on how to load, read different content from different sources and how to behave while rendering the web pages.</p><h3><strong>Few security headers that web developers can use to enhance security</strong></h3><h4>Content Security Policy (CSP) header:</h4><blockquote>CSP is used to define which resources are allowed to be loaded by the browser or from which source browser can load resources. For example, developers can use CSP to specify which domains/ files are allowed to execute JavaScript code, images or CSS files.</blockquote><blockquote>CSP is an effective security measure against XSS attacks and helps to prevent the execution of malicious scripts</blockquote><h4>Strict-Transport-Security (STS) header</h4><blockquote>STS is a security header that ensures that all communication between the browser and the server happens over an encrypted HTTPS connection and reject any non-HTTPS requests. This prevents any potential eavesdropping or man-in-the-middle attacks.</blockquote><h4>X-XSS-Protection header</h4><blockquote>X-XSS-Protection header helps to prevent cross-site scripting (XSS) attacks by telling the browser to block any malicious scripts. This header instructs the browser to enable the built-in XSS protection feature and block any scripts that could potentially be harmful.</blockquote><h4>X-Content-Type-Options header</h4><blockquote>X-Content-Type-Options header tells the browser to only accept the content type specified in the response headers, preventing content sniffing attacks. This header instructs the browser to follow the declared MIME type in the response and prevent any malicious code that could be disguised as another file type.</blockquote><h4>X-Frame-Options header</h4><blockquote>X-Frame-Options header prevents clickjacking attacks by preventing a page from being displayed in an iframe. This header instructs the browser to deny any attempt to load the web page in an iframe, protecting against clickjacking attacks.</blockquote><h4>Referrer-Policy</h4><blockquote>Referrer-Policy allows web developers to control how much information is sent when a user navigates from one page to another as a referrer header. The referrer header contains the URL of the page that the user was on before navigating to the current page.</blockquote><h4>Permissions-Policy</h4><blockquote>Permissions-Policy allows web developers to control and restrict the features and APIs that a web page can access or use. This header is used to provide more granular control over the permissions that a web application requires to function properly.</blockquote><h3><strong>Is it mandatory to use Security headers</strong></h3><p>It is <strong><em>not mandatory, but it is highly recommended</em></strong> as a best practice to improve the security of your web application.</p><h3>How to add Security headers to your applications</h3><p>Based on the application tech stack there are different ways that we can apply security headers.</p><blockquote>If you are using Azure front-door for your application see following documentation provided by Azure. <a href="https://learn.microsoft.com/en-us/azure/frontdoor/front-door-security-headers">https://learn.microsoft.com/en-us/azure/frontdoor/front-door-security-headers</a></blockquote><p>If your are using ASP.NET Core MVC in statup.cs class you can add following code segment</p><pre>app.Use(async (context, next) =&gt;<br>            {<br>                context.Response.Headers.Add(&quot;X-Xss-Protection&quot;, &quot;1; mode=block&quot;);<br>                context.Response.Headers.Add(&quot;X-Content-Type-Options&quot;, &quot;nosniff&quot;);<br>                context.Response.Headers.Add(&quot;Content-Security-Policy&quot;, &quot;default-src &#39;none&#39;; script-src &#39;self&#39; [WEBSITE_URL] &#39;unsafe-inline&#39; &#39;unsafe-hashes&#39; &#39;unsafe-eval&#39;; style-src &#39;self&#39; [WEBSITE_URL] &#39;unsafe-inline&#39; &#39;unsafe-inline&#39; &#39;unsafe-eval&#39;; connect-src &#39;self&#39; wss: [WEBSITE_URL]; font-src &#39;self&#39; data: [WEBSITE_URL]; img-src &#39;self&#39; data: [WEBSITE_URL]; frame-src &#39;self&#39;&quot;);<br>                context.Response.Headers.Add(&quot;X-Frame-Options&quot;, &quot;SAMEORIGIN&quot;);<br>                context.Response.Headers.Add(&quot;Permissions-Policy&quot;, &quot;accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), usb=()&quot;);<br>                context.Response.Headers.Add(&quot;Report-To&quot;, @&quot;{ &quot;&quot;group&quot;&quot;: &quot;&quot;default&quot;&quot;, &quot;&quot;max_age&quot;&quot;: 10886400, &quot;&quot;endpoints&quot;&quot;: [{ &quot;&quot;url&quot;&quot;: &quot;&quot;&quot;&quot; }] }&quot;);<br>                context.Response.Headers.Add(&quot;NEL&quot;, &quot;{&#39;report_to&#39;:&#39;default&#39;,&#39;max_age&#39;:31536000,&#39;include_subdomains&#39;:true}&quot;);<br>       context.Response.Headers.Add(&quot;Referrer-Policy&quot;, &quot;strict-origin&quot;);<br>  context.Response.Headers.Add(&quot;feature-policy&quot;, &quot;accelerometer &#39;none&#39;; camera &#39;none&#39;; geolocation &#39;none&#39;; gyroscope &#39;none&#39;; magnetometer &#39;none&#39;; microphone &#39;none&#39;; payment &#39;none&#39;; usb &#39;none&#39;&quot;);<br>  context.Response.Headers.Add(&quot;Expect-CT&quot;, &quot;max-age=0, report-uri=&#39;[WEBSITE_URL]&#39;&quot;);<br>            });</pre><p>Above one is a sample but I’ll share another article with detailed explanation on the implementation.</p><p>OWASP is a great free tool that we can use to detect if your site has any vulnerabilities related to security headers.</p><p><a href="https://owasp.org/">OWASP Foundation, the Open Source Foundation for Application Security | OWASP Foundation</a></p><p>The following website is one free tool you can use for your reference. But there are lots of different tools available on the internet that we can use for free to scan the security headers.</p><p><a href="https://securityheaders.com/">Analyse your HTTP response headers</a></p><p>You can find more details related to security headers on</p><ul><li><a href="https://cheatsheetseries.owasp.org/cheatsheets/HTTP_Headers_Cheat_Sheet.html">HTTP Headers - OWASP Cheat Sheet Series</a></li><li><a href="https://owasp.org/www-project-secure-headers/">OWASP Secure Headers Project</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca69f465fd4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Are you using the right process in Software Development ?]]></title>
            <link>https://medium.com/@nayanajith89/are-you-using-the-right-process-in-software-development-8d7a1af2ff2b?source=rss-9c2e2aa621ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d7a1af2ff2b</guid>
            <category><![CDATA[sdlc-methodologies]]></category>
            <category><![CDATA[process-improvement]]></category>
            <category><![CDATA[process]]></category>
            <category><![CDATA[sdlc]]></category>
            <dc:creator><![CDATA[Nayanajith Pilapitiya]]></dc:creator>
            <pubDate>Fri, 14 Apr 2023 16:41:08 GMT</pubDate>
            <atom:updated>2023-04-14T16:41:08.005Z</atom:updated>
            <content:encoded><![CDATA[<h3>Are you using the right process in Software Development ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FUgSi8RZKjq5rAGbKzATqw.jpeg" /></figure><p>Process in simple terms is a set of steps, guidelines, or rules which a team follows to improve the Software Development Life Cycle.</p><p>It is always better to have a good process because they do help to ensure consistency, quality, productivity, and predictability. But to have a successful outcome you need to maintain the right balance between the process and the team. If not it might be an overhead to the team and the results will not be what is expected from a process. Following are some advantages when using a process and disadvantages when things are over-complicated.</p><h3>Advantages</h3><p><strong>Efficiency:</strong> A well-defined process can help teams work more efficiently by providing clear guidelines on how to perform certain tasks and practice with time, making it a habit, and reducing time on recurring tasks.</p><p><strong>Quality:</strong> A good process can help to have high-quality software by defining standards for requirement gathering, estimations, planning, coding, testing, and deployment.</p><p><strong>Consistency:</strong> A process makes sure that all the members across the team follow the same approach, which results in consistent quality which helps to reduce errors.</p><p><strong>Communication/ Collaboration:</strong> Processes can help teams communicate and work together more effectively by defining roles and responsibilities, and by providing a clear understanding of project timelines, milestones, and deliverables.</p><h3>What happens if your process is not what you need?</h3><p><strong>Over complication:</strong> If processes are over-complicated, with too many steps, too many checkpoints, and redundant tasks it can have an impact on productivity and drastically slow down the software development, test, release process.</p><p><strong>Rigidity/Inflexibility:</strong>When processes are too rigid, it will have an impact on the innovation, agility, continuity, and difficulty to accommodate changes in the project.</p><p><strong>Time-consuming:</strong> Processes should help to utilize time productively but it can become a burden if it requires too much time and effort to follow and track and it will take the teams focus away from the actual development work.</p><h3>How to identify what is best for the team?</h3><p>There are lots of processes out there in the industry practiced by different organizations. For example</p><ol><li>Waterfall</li><li>Agile</li><li>DevOps</li><li>Lean</li><li>Scrum</li><li>Kanban</li><li>Six Sigma</li><li>Rational Unified Process (RUP)</li><li>Extreme Programming (XP)</li></ol><p>When setting up a process you can follow already implemented standards, similar to above or you can use a hybrid model which has different components from different practices. But when implementing such a process,you should have good practice, knowledge, and more importantly it should be done with extreme caution.</p><h3>Key factors to consider when setting up a process</h3><blockquote>Goals and objectives of the project</blockquote><blockquote>Commitment from the team members, management, and customers</blockquote><blockquote>Well-defined roles and responsibilities for all the stakeholders</blockquote><blockquote>Proper workflows</blockquote><blockquote>Adaptability and flexibility of the process and the stakeholders</blockquote><blockquote>Qualitative and quantitative measures</blockquote><blockquote>Space for continuous improvement</blockquote><blockquote>Training and support</blockquote><blockquote>Resources and cost for implementation</blockquote><p>Following the best suitable process is important and will have a significant improvement in quality, productivity, and clarity. Though you have a great process it has to be followed properly by all the stakeholders to have the right outcome.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d7a1af2ff2b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using a framework for development.]]></title>
            <link>https://medium.com/@nayanajith89/using-a-framework-for-development-23f34f187d9c?source=rss-9c2e2aa621ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/23f34f187d9c</guid>
            <category><![CDATA[design]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[boilerplate-code]]></category>
            <category><![CDATA[framework]]></category>
            <category><![CDATA[architecture]]></category>
            <dc:creator><![CDATA[Nayanajith Pilapitiya]]></dc:creator>
            <pubDate>Mon, 06 Feb 2023 03:14:56 GMT</pubDate>
            <atom:updated>2023-02-06T03:15:15.984Z</atom:updated>
            <content:encoded><![CDATA[<h3>Using a framework for application development.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tOl_CTZxOdLW7RbHeEUA_A.jpeg" /></figure><p>As developers there are situations where we have to setup a project from scratch. But is it really worth it ?</p><p>When you are architecture a project there are lots of aspects we have to think as a developer. For a few things for example</p><ol><li>Security</li><li>Performance</li><li>Extendability</li><li>Maintainability</li><li>Timeline of the project and is it compatibility with the learning curve ?</li></ol><p>When we working on a project from scratch, the work load will have a huge impact different aspects of the project. Few points are…</p><ol><li>Time of the deliverable have an impact as the initial work is really high.</li><li>Cost will have a significant impact with the time and the effort needs to be included.</li><li>Need extensive testing as the solution was build from the scratch.</li></ol><p>Most of the time we will be re-inventing the wheel which was already there.</p><p>What are the aspects need to look in to when select a framework ?</p><ol><li>Why you want to use a framework?</li><li>Is it a full fledged framework ?</li><li>Rating / usage and the reviews.</li><li>Learning curve, available documentations and the team skill set.</li><li>Is the architecture is what you are looking for ?</li><li>Performance</li><li>Security</li></ol><p>Selecting a framework is not an easy task and it will not solve all the problems you have in a project. It will not suit for all the scenarios. So understanding the underline tools and architecture of the framework is a must before starting.</p><p>It’s not required to use a framework to the each an every project. It might bring extra complexity and prone to errors if there are lots of unwanted components.</p><p>As a .NET person I would like to share few boilerplate/ frameworks on .NET platforms which I believe are really good. These are bootstrap framework but there are lot’s of domain based frameworks as well.</p><ul><li><a href="https://github.com/aspnetboilerplate/aspnetboilerplate">GitHub - aspnetboilerplate/aspnetboilerplate: ASP.NET Boilerplate - Web Application Framework</a></li><li><a href="https://github.com/ardalis/CleanArchitecture">GitHub - ardalis/CleanArchitecture: Clean Architecture Solution Template: A starting point for Clean Architecture with ASP.NET Core</a></li><li><a href="https://abp.io/">ABP Framework - Open Source Web Application Framework</a></li><li><a href="https://github.com/kgrzybek/modular-monolith-with-ddd">GitHub - kgrzybek/modular-monolith-with-ddd: Full Modular Monolith application with Domain-Driven Design approach.</a></li></ul><p>And using a framework has it’s own risk. So review the framework and make sure .you have advantage over using that particular framework.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23f34f187d9c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Corda 5 ?]]></title>
            <link>https://medium.com/@nayanajith89/why-corda-5-1311a831c854?source=rss-9c2e2aa621ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/1311a831c854</guid>
            <category><![CDATA[corda5]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Nayanajith Pilapitiya]]></dc:creator>
            <pubDate>Mon, 30 Jan 2023 06:30:20 GMT</pubDate>
            <atom:updated>2023-01-30T06:30:43.515Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why Corda 5 ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*wjQHuZ4sn9GhlXo2.png" /></figure><p>I have been working with Corda in an out for last one year and mostly with 4.8 and 4.9 versions. And the start was not a dream start. The complexity and the confused documentations tend to mislead a starters. Following are few things which gives edge. Following are a quick overview on Corda 5.</p><h4>CorDapp Standard Development Environment (CSDE)</h4><p>Main reason I love Corda 5 already even it still in the early stage of development is CorDapp Standard Development Environment (CSDE). CSDE to me is a bootstrap for Corda. As developer I can start the application development with less effort on the configuration. CSDE contains basic gradle configuration with gradle basic tasks as well.</p><p>And few other points I’d like to highlights are</p><blockquote><strong>Out-of-the-box support for Restful-API.</strong></blockquote><blockquote><strong>Out-of-the-box support for containerization.</strong></blockquote><blockquote><strong>Corda Packages</strong></blockquote><blockquote><strong>Clear documentations compared to previous versions.</strong></blockquote><p>Corda 5 is still in the early stage. We should be able to see more existing stuff with next phases.</p><p>In coming articles I am planing to deep dive in to Corda 5 and stay tuned.</p><p>To learn more you can refer following resources.</p><ul><li><a href="https://docs.r3.com/en/platform/corda/5.0-dev-preview-2.html">Corda 5 Developer Preview 2</a></li><li><a href="https://github.com/corda/CSDE-cordapp-template-kotlin">GitHub - corda/CSDE-cordapp-template-kotlin: Template Repo which provide CSDE functions and getting started Cordapp template</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1311a831c854" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure chat-bot with React]]></title>
            <link>https://medium.com/@nayanajith89/azure-chat-bot-with-react-3eebb00473fa?source=rss-9c2e2aa621ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/3eebb00473fa</guid>
            <dc:creator><![CDATA[Nayanajith Pilapitiya]]></dc:creator>
            <pubDate>Mon, 16 Jan 2023 07:46:45 GMT</pubDate>
            <atom:updated>2023-01-16T08:20:49.722Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JyD6qHySoIf6sIrh85RShw.jpeg" /></figure><p>In my previous article I have demonstrated how we can create Azure chat-bot and connect it with Angular website. This is an extended article to the it. Please see my previous article <a href="https://medium.com/@nayanajith89/implement-azure-chat-bot-with-asp-net-core-mvc-and-angular-6623fc1e4617">here</a>.</p><p>In this article I am going to demonstrate how can we integrate Azure chat-bot with React application. In this article I will not cover basics on Azure and React. For this exercise please refer my Azure chat-bot article and follow until “Step 04”, and this article will replace “Step 05” with React instead angular.</p><h4>Step 01 | Create React project</h4><p>You can use following script to create a React application.</p><pre>npx create-react-app my-chatapp --template typescript</pre><h4>Step 02 | Import “botframework-webchat”</h4><pre>npm i botframework-webchat</pre><p>Step 03 | Create Component for Chat-bot and copy following to the new component</p><pre>import { useMemo, useState, useEffect } from &quot;react&quot;<br>import ReactWebChat, { createDirectLine } from &quot;botframework-webchat&quot;<br><br><br>export const ChatBot = () =&gt; {<br>  const [token, setToken] = useState(&quot;&quot;)<br>  const directLine = useMemo(() =&gt; createDirectLine({ token }), [token])<br><br>const requestOptions = {<br>    method: &#39;POST&#39;,<br>    headers: { &#39;Content-Type&#39;: &#39;application/json&#39; },<br>};<br><br>const fetchData = async () =&gt; {<br>    const response = await fetch(&quot;https://localhost/api/chatbot&quot;, requestOptions)<br>    const data = await response.json()<br>    setToken(data.data.token)<br>  }<br><br>  useEffect(() =&gt; {<br>    fetchData()<br>  }, [])<br><br><br>  return (<br>    &lt;&gt;<br>      &lt;div className=&quot;azure-chatbot&quot;&gt;<br>        {&lt;ReactWebChat directLine={directLine} /&gt;}<br>      &lt;/div&gt;<br>    &lt;/&gt;<br>  )<br>}<br>export default ChatBot</pre><p>To connect with API and get the token best practice is to define service, since this is a demo I have used in the same component.</p><h4>Step 03 | Update “App.tsx”</h4><pre>import React from &#39;react&#39;;<br>import logo from &#39;./logo.svg&#39;;<br>import &#39;./App.css&#39;;<br>import ChatBot from &#39;./components/chatbot&#39;;<br><br>function App() {<br>  return (<br>    &lt;div className=&quot;App&quot;&gt;<br>      &lt;ChatBot/&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><h4>Step 04 | Add some style</h4><p>To show the chat-bot as a normal widget I have used following style. But you can use your own way to style it.</p><pre>.azure-chatbot{<br>  position: fixed;<br>  z-index: 1000;<br>  right: 1%;<br>  bottom: 7%;<br>  width: 25%;<br>  height: 40%;<br>}</pre><p>Please see the working sample for <a href="https://github.com/pilacst/azure-chatbot-reactjs">React on GitHub</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3eebb00473fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implement Azure Chat-bot with ASP.NET Core Web API and Angular]]></title>
            <link>https://medium.com/@nayanajith89/implement-azure-chat-bot-with-asp-net-core-mvc-and-angular-6623fc1e4617?source=rss-9c2e2aa621ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/6623fc1e4617</guid>
            <dc:creator><![CDATA[Nayanajith Pilapitiya]]></dc:creator>
            <pubDate>Tue, 10 Jan 2023 17:50:11 GMT</pubDate>
            <atom:updated>2024-02-13T15:09:22.317Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JyD6qHySoIf6sIrh85RShw.jpeg" /></figure><p>Chat-bot is a software solution which simulate human like conversation in order to improve customer engagement. With the improvement AI now the chat-bot is more intelligent, more conversational and more realistic.</p><p>Azure chat-bot is one of leading Chat-bot solution provider and today I am going to demonstrate how to setup Azure Chat-bot for your application without using Ifame. The technology will be Angular and ASP.NET CORE Web API . This article will not cover ASP.NET CORE Web API and Angular basics. This includes following steps</p><ol><li>Create a language resource on your azure portal</li><li>Create a Cognitive service &amp; custom question answering knowledge base.</li><li>Create Bot</li><li>Create API</li><li>Create front-end</li></ol><h4>Stage: 01 | Create a language resource on your azure portal.</h4><p>Step: 01 |</p><p>Go the the azure portal and select language services from azure portal then click create. Then in the next step use <strong>Custom questions and answering</strong> option</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*208tl-eLY_CbrELu7MaSCw.png" /></figure><p>Step: 02 |</p><p>Next click “Continue to create your resource”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*X-Sfy2i15eB0Pp3wOvXNiw.png" /><figcaption>Create language source.</figcaption></figure><blockquote><strong>Subscription:</strong> The Azure subscription you are using.<br><strong>Resource group:</strong> Can use your existing subscription or create a new one.<br><strong>Name:</strong> A unique name for your Language resource.<br><strong>Pricing tier:</strong> Any available tier at your convenience.<br><strong>Azure search region:</strong> Any available location at your convenience.<br><strong>Azure search pricing tier:</strong> Any available tier at your convenience.</blockquote><p>Provide the “resource group” and “name” and “pricing tier” finally click on “Review + create”.</p><p>Once the process is completed you can see under all resources following services are deployed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oJFXDqK5FVL1xziHPFtUKg.png" /><figcaption>Created resources.</figcaption></figure><h4>Stage: 02 | Create a Cognitive service</h4><p>Step: 01 |</p><p>Login to Language service using your azure credentials (Use following URL)</p><pre>https://language.cognitive.azure.com/</pre><p>Step: 02 |</p><p>Once logged in to the Language service use your existing subscription and you can use the Language resource created in the previous step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*sQDX9awCGKi6DM2vgvjzoA.png" /><figcaption>Landing page of <a href="https://language.cognitive.azure.com/">https://language.cognitive.azure.com/</a></figcaption></figure><blockquote><strong>Azure directory:</strong> The Azure directory containing your subscription.<br><strong>Azure subscription:</strong> Your Azure subscription.<br><strong>Language resource:</strong> The Language resource you created previously.</blockquote><p>Step: 03 |</p><p>Then click on “Create new” button and select “Custom questions and answering” option and follow next steps in the screen shots.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*sbxvRvgTi5LEeB50eeS8cw.png" /><figcaption>Create new project.</figcaption></figure><p>Step: 04 |</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*ypNoulxT1lMDgPfloG7LxA.png" /><figcaption>Providing basic information for the project.</figcaption></figure><blockquote><strong>Name: </strong>Unique name for your project.<br><strong>Description:</strong> Description to elaborate your project.<br><strong>Source language: </strong>Preferred language .<br><strong>Default answer when no answer is returned:</strong> Answer when nothing to return from the knowledge base.</blockquote><p>Step: 06 |</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*jIiuXYAJqnlthDk8AMTf4g.png" /><figcaption>Complete the project.</figcaption></figure><p>Finally click on the “Create project” button and you will have your Custom questions and answering service ready.</p><p>Step: 07 |</p><p>Then you can click “Add source” and add relevant websites, documents, files to improve knowledge base. More details you give the bot will have more proper answers for the questions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hq2MPQNDrLJmHQ_zf74Aig.png" /><figcaption>Add sources to get information for the bot.</figcaption></figure><p>Step: 08 |</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WoYYPtgKnq6iUDixQ2exjw.png" /><figcaption>Add custom questions and answers to bot.</figcaption></figure><p>Step: 10 |</p><p>Then finally we have to deploy the language service in order to use in with Azure bot service. Click on the “Deploy knowledge base” on the left side menu bar. Once you redirect to following page click on the “Deploy” tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0ryOzfhPffQrmxmDjMso1Q.png" /><figcaption>Deploy knowledge base for use with bot.</figcaption></figure><h4>Stage: 03 | Create Bot</h4><p>Step: 01 |</p><p>Once the Cognitive service is complete next step is to create a bot. In order to do that click on the “Create a bot” button below in the “Deploy knowledge base” page. You will be redirected to Custom deployment page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*YMPHOkWevfDLzhQbKjRt1A.png" /><figcaption>Create bot on azure.</figcaption></figure><blockquote><strong>Subscription</strong>: Your Azure subscription.<br><strong>Resource group</strong>: The resource group containing your Language resource.<br><strong>Resource group location</strong>: The same location as your Language service.<br><strong>Bot handle:</strong> Unique name for the bot.<br><strong>Pricing tier</strong>: Select suitable pricing tier.<br><strong>Creation type</strong>: Choose on your requirement for this demo I am using “Create new User-assigned manged identity”</blockquote><p>Step: 02 |</p><p>Provide the required information and then go the the next page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/1*rzC8vJALEJH8TrcPK_XE-Q.png" /><figcaption>Bots web app details.</figcaption></figure><blockquote><strong>App name</strong>: a unique name for the app and it will have .azurewebsites.net appended automatically<br><strong>SDK language</strong>: Choose either C# or Node.js for this project I am using C#.<br><strong>Language Resource Key</strong>: See the below step 03 to where to find the key. <strong>Language project name:</strong> Unique name for the project<br><strong>Language service end point hostname:</strong> Auto generate<br><strong>Subscription Id:</strong> Auto filled<br>Resource group name: Auto filled</blockquote><p>Step: 03 |</p><p>You can find the language resource key inside language service we have created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*ZtAX__LpkofTgbp7EWUyFg.png" /><figcaption>Get the language resource key to use in “Bots web app details”.</figcaption></figure><p>Then create the bot by clicking the “Review + create”.</p><p>Step: 04 |</p><p>Once the deployment completed go the “Azure bot” =&gt; “Channels” and click default site</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Wp-xIRfuMqKOqrytrDntQ.png" /><figcaption>Secret keys for the bot.</figcaption></figure><p>you can see the secret key on the API project to access the chatbot.</p><h4>Stage: 04 | Create API</h4><p>Once the above azure setup is complete we can start working on the integration part.</p><p>Step: 01 |</p><p>Create an ASP.NET Core Web API application and use flowing code snip to create Controller which handle the connection to the Azure Chat-bot</p><pre>    [Route(&quot;api/connect&quot;)]<br>    [ApiController]<br>    [EnableCors(&quot;CorsPolicy&quot;)]<br>    public class AzureChatBotController: ControllerBase {<br>        private readonly string azureChatBotSecret;<br>        private readonly string azureChatUrl;<br>        private readonly IConfiguration _configuration;<br>        public AzureChatBotController(IConfiguration configuration) {<br>            _configuration = configuration;<br>            azureChatBotSecret = _configuration.GetSection(CommonConstantsants.AzureChatBotSecret).Value;<br>            azureChatUrl = _configuration.GetSection(CommonConstantsants.AzureChatBotUrl).Value;<br>        }<br><br>        [HttpPost(&quot;chatBot&quot;)]<br>        public async Task&lt;ActionResult&gt; ChatBot() {<br>            var secret = azureChatBotSecret;<br><br>            HttpClient client = new HttpClient();<br><br>            HttpRequestMessage request = new HttpRequestMessage(<br>                HttpMethod.Post, azureChatUrl);<br><br>            request.Headers.Authorization = new AuthenticationHeaderValue(&quot;Bearer&quot;, secret);<br><br>            var userId = $&quot;dl_{Guid.NewGuid()}&quot;;<br><br>            request.Content = new StringContent(<br>                JsonConvert.SerializeObject(<br>                    new { User = new { Id = userId } }),<br>                    Encoding.UTF8,<br>                    &quot;application/json&quot;);<br><br>            var response = await client.SendAsync(request);<br>            string token = String.Empty;<br><br>            if(response.IsSuccessStatusCode) {<br>                var body = await response.Content.ReadAsStringAsync();<br>                token = JsonConvert.DeserializeObject&lt;DirectLineTokenDto&gt;(body).token;<br>            }<br><br>            var config = new ChatConfigDto() {<br>                Token = token,<br>                UserId = userId<br>            };<br><br>            return Ok(config);<br>        }<br>    }</pre><p>Step: 02 |</p><p>Use the following appsettig.json configuration to connect to the chatbot. The secret you can find under “Azure bot” =&gt; “Chennel” =&gt; “Default site” mention in “Stage 03 step 04”.</p><pre>&quot;AzureChatBot&quot;: {<br>    &quot;Secret&quot;: &quot;&quot;,<br>    &quot;Url&quot;: &quot;https://directline.botframework.com/v3/directline/tokens/generate&quot;<br>  },</pre><h4>Stage: 05 |<strong>Create front-end</strong></h4><p>Then create your Angular app and use following code to show the chat-bot on your application.</p><p>Step: 01 |</p><p>First you have to add following script file in the index.html.</p><pre>&lt;script src=&quot;https://cdn.botframework.com/botframework-webchat/latest/webchat.js&quot;&gt;&lt;/script&gt;</pre><p>Step: 02 |</p><p>Then you have to add a div to embedded the chat widget and button to toggle chat window.</p><pre>&lt;div id=&quot;webchat&quot; class=&quot;webchat&quot; role=&quot;main&quot;&gt;&lt;/div&gt;<br>&lt;button&quot; id=&quot;webchat-button&quot; class=&quot;webchat-button btn btn-primary&quot; role=&quot;main&quot; &gt;&lt;i<br>      id=&quot;webchat-icon&quot; class=&quot;fa fa-comment&quot;&gt;&lt;/i&gt;&lt;/button&gt;</pre><p>Step: 03 |</p><p>Next to change your chat widget styling you can use following section.</p><pre>&lt;script&gt;<br><br>      // &quot;styleSet&quot; is a set of CSS rules which are generated from &quot;styleOptions&quot;<br>      const styleSet = window.WebChat.createStyleSet({<br>        bubbleBackground: &#39;rgba(0, 0, 255, .1)&#39;,<br>        bubbleFromUserBackground: &#39;rgba(0, 255, 0, .1)&#39;,<br><br>        botAvatarImage: &#39;&#39;,<br>        botAvatarInitials: &#39;Downsizer&#39;,<br>        userAvatarImage: &#39;&#39;,<br>        userAvatarInitials: &#39;WC&#39;,<br>        rootHeight: &#39;100%&#39;,<br>        rootWidth: &#39;60%&#39;<br>      });<br><br>      // After generated, you can modify the CSS rules<br>      styleSet.textContent = {<br>        ...styleSet.textContent,<br>        fontFamily: &quot;&#39;Comic Sans MS&#39;, &#39;Arial&#39;, sans-serif&quot;,<br>        fontWeight: &#39;bold&#39;<br>      };<br>&lt;/script&gt;</pre><p>Step: 04 |</p><p>Finally add following section to connect with your API endpoint.</p><pre>&lt;script&gt;<br>      (async function () {<br>        const res = await fetch(&#39;https://localhost:5443/api/connect/chatBot&#39;,<br>          {<br>            &quot;method&quot;: &quot;POST&quot;,<br>            &quot;headers&quot;: {<br>              &#39;Content-Type&#39;: &#39;application/json&#39;,<br>              &#39;Accept&#39;: &#39;*/*&#39;<br>            }<br>          }<br>        );<br>        const { token, userId } = await res.json();<br><br>        window.WebChat.renderWebChat(<br>          {<br>            directLine: window.WebChat.createDirectLine({ token }),<br>            userID: userId,<br>            locale: &#39;en-US&#39;,<br>            username: &#39;Web Chat User&#39;,<br>            locale: &#39;en-US&#39;,<br>            // Passing &#39;styleSet&#39; when rendering Web Chat<br>            styleSet<br>          },<br>          document.getElementById(&#39;webchat&#39;)<br>        );<br><br>        document.querySelector(&#39;#webchat &gt; *&#39;).focus();<br>      })().catch(err =&gt; console.error(err));<br>&lt;/script&gt;</pre><h4>Stage: 06 |Output</h4><p>Once all completed your output will be get something similar to following. Please note that in order to show this as a chat widget I have used few extra CSS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/1*Xq9abdDKSi_g6PDcWcLcpw.png" /></figure><p>References:</p><pre>https://learn.microsoft.com/en-us/training/modules/build-faq-chatbot-qna-maker-azure-bot-service/1-introduction<br>https://www.npmjs.com/package/ngx-microsoft-bot-framework<br>https://github.com/microsoft/BotFramework-WebChat<br></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6623fc1e4617" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular multi environment deployment with Azure Dev-ops]]></title>
            <link>https://medium.com/@nayanajith89/angular-multi-environment-deployment-with-azure-dev-ops-20b125e32440?source=rss-9c2e2aa621ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/20b125e32440</guid>
            <dc:creator><![CDATA[Nayanajith Pilapitiya]]></dc:creator>
            <pubDate>Fri, 30 Dec 2022 17:41:35 GMT</pubDate>
            <atom:updated>2022-12-30T17:49:19.623Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*jcXChWKNLOa3TO8Dg_mGsg.png" /><figcaption>Angular with Azure Dev-Ops</figcaption></figure><p>When you deploy an Angular website you may encounter situations where you wanted different behaviors on each environment (Dev / UAT/ Prod). For example you might want to use different styles, theme, analytic tools in different stages. We will discuss it today how can we achieve it for Angular with azure DevOps.</p><p>In order to do that the first thing we have to modify is angualr.json file. In angualr.json file you can see a section call “configurations” under configurations you can define different configurations for different environments. Please see the sample below.</p><pre>&quot;configurations&quot;: {<br>            &quot;Dev&quot;: {<br>              &quot;fileReplacements&quot;: [<br>                {<br>                  &quot;replace&quot;: &quot;src/environments/environment.ts&quot;,<br>                  &quot;with&quot;: &quot;src/environments/Dev/environment.dev.ts&quot;<br>                }<br>              ],<br>              &quot;index&quot;: &quot;src/environments/Dev/index.html&quot;,<br>              &quot;optimization&quot;: true,<br>              &quot;outputHashing&quot;: &quot;all&quot;,<br>              &quot;sourceMap&quot;: false,<br>              &quot;extractCss&quot;: true,<br>              &quot;namedChunks&quot;: false,<br>              &quot;extractLicenses&quot;: true,<br>              &quot;vendorChunk&quot;: false,<br>              &quot;buildOptimizer&quot;: true,<br>              &quot;budgets&quot;: [<br>                {<br>                  &quot;type&quot;: &quot;initial&quot;,<br>                  &quot;maximumWarning&quot;: &quot;12mb&quot;,<br>                  &quot;maximumError&quot;: &quot;12mb&quot;<br>                },<br>                {<br>                  &quot;type&quot;: &quot;anyComponentStyle&quot;,<br>                  &quot;maximumWarning&quot;: &quot;6kb&quot;,<br>                  &quot;maximumError&quot;: &quot;10kb&quot;<br>                }<br>              ]<br>            },<br>            &quot;QA&quot;: {<br>              &quot;fileReplacements&quot;: [<br>                {<br>                  &quot;replace&quot;: &quot;src/environments/environment.ts&quot;,<br>                  &quot;with&quot;: &quot;src/environments/QA/environment.qa.ts&quot;<br>                }<br>              ],<br>              &quot;index&quot;: &quot;src/environments/QA/index.html&quot;,<br>              &quot;optimization&quot;: true,<br>              &quot;outputHashing&quot;: &quot;all&quot;,<br>              &quot;sourceMap&quot;: false,<br>              &quot;extractCss&quot;: true,<br>              &quot;namedChunks&quot;: false,<br>              &quot;extractLicenses&quot;: true,<br>              &quot;vendorChunk&quot;: false,<br>              &quot;buildOptimizer&quot;: true,<br>              &quot;budgets&quot;: [<br>                {<br>                  &quot;type&quot;: &quot;initial&quot;,<br>                  &quot;maximumWarning&quot;: &quot;12mb&quot;,<br>                  &quot;maximumError&quot;: &quot;12mb&quot;<br>                },<br>                {<br>                  &quot;type&quot;: &quot;anyComponentStyle&quot;,<br>                  &quot;maximumWarning&quot;: &quot;6kb&quot;,<br>                  &quot;maximumError&quot;: &quot;10kb&quot;<br>                }<br>              ]<br>            },<br>            &quot;staging&quot;: {<br>              &quot;fileReplacements&quot;: [<br>                {<br>                  &quot;replace&quot;: &quot;src/environments/environment.ts&quot;,<br>                  &quot;with&quot;: &quot;src/environments/Staging/environment.stag.ts&quot;<br>                }<br>              ],<br>              &quot;index&quot;: &quot;src/environments/Staging/index.html&quot;,<br>              &quot;optimization&quot;: true,<br>              &quot;outputHashing&quot;: &quot;all&quot;,<br>              &quot;sourceMap&quot;: false,<br>              &quot;extractCss&quot;: true,<br>              &quot;namedChunks&quot;: false,<br>              &quot;extractLicenses&quot;: true,<br>              &quot;vendorChunk&quot;: false,<br>              &quot;buildOptimizer&quot;: true,<br>              &quot;budgets&quot;: [<br>                {<br>                  &quot;type&quot;: &quot;initial&quot;,<br>                  &quot;maximumWarning&quot;: &quot;12mb&quot;,<br>                  &quot;maximumError&quot;: &quot;12mb&quot;<br>                },<br>                {<br>                  &quot;type&quot;: &quot;anyComponentStyle&quot;,<br>                  &quot;maximumWarning&quot;: &quot;6kb&quot;,<br>                  &quot;maximumError&quot;: &quot;10kb&quot;<br>                }<br>              ]<br>            },<br>            &quot;production&quot;: {<br>              &quot;fileReplacements&quot;: [<br>                {<br>                  &quot;replace&quot;: &quot;src/environments/environment.ts&quot;,<br>                  &quot;with&quot;: &quot;src/environments/Prod/environment.prod.ts&quot;<br>                }<br>              ],<br>              &quot;index&quot;: &quot;src/environments/Prod/index.html&quot;,<br>              &quot;optimization&quot;: true,<br>              &quot;outputHashing&quot;: &quot;all&quot;,<br>              &quot;sourceMap&quot;: false,<br>              &quot;extractCss&quot;: true,<br>              &quot;namedChunks&quot;: false,<br>              &quot;extractLicenses&quot;: true,<br>              &quot;vendorChunk&quot;: false,<br>              &quot;buildOptimizer&quot;: true,<br>              &quot;budgets&quot;: [<br>                {<br>                  &quot;type&quot;: &quot;initial&quot;,<br>                  &quot;maximumWarning&quot;: &quot;12mb&quot;,<br>                  &quot;maximumError&quot;: &quot;12mb&quot;<br>                },<br>                {<br>                  &quot;type&quot;: &quot;anyComponentStyle&quot;,<br>                  &quot;maximumWarning&quot;: &quot;6kb&quot;,<br>                  &quot;maximumError&quot;: &quot;10kb&quot;<br>                }<br>              ]<br>            }<br>          }</pre><p>In the above sample you can see within configuration section I have define different blocks for different environments.</p><p>Then you have to create the folders and respective files under environment folder. Please see the sample screenshot</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*vCAWAmpsFvq5vFzxAnHI_Q.png" /></figure><p>Once all the above changes are completed we have a simple change to do in the Azure DevOps pipeline for the Angular project.</p><p>Select the pipeline and update the build command to</p><blockquote>build — configuration={configurationName}</blockquote><p>Please see the screenshot below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*whfymMwPUDzzGJmLGxFbBg.png" /></figure><p>With this simple change you can define different behaviors/configurations on each environments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20b125e32440" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Connect App service with Azure key vault without exposing Key-vault password.]]></title>
            <link>https://medium.com/@nayanajith89/connect-app-service-with-azure-key-vault-without-exposing-key-vault-password-d3abf55f7ef9?source=rss-9c2e2aa621ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3abf55f7ef9</guid>
            <dc:creator><![CDATA[Nayanajith Pilapitiya]]></dc:creator>
            <pubDate>Thu, 27 Oct 2022 16:11:28 GMT</pubDate>
            <atom:updated>2022-10-27T16:11:28.731Z</atom:updated>
            <content:encoded><![CDATA[<p>Azure key-vault is an azure cloud service that provides a secure store for secrets and certificates. You can store any password, token, key etc..</p><p>There are different ways that you can use to integrate the azure key-vault with your web application. Today I am going to demonstrate to you how to use Azure key-vault with ASP.NET Core web app (MVC) hosted in the App Service with Azure service principal. This option will allow you to avoid adding any secret, password, token in the appsetting.json including Key-vault connection related password, secret or token.</p><p>This article will not cover the ASP.NET Core web app (MVC) project creation steps and the basics of ASP.NET Core web app (MVC).</p><p><strong>Step 01</strong></p><p>Create an ASP.NET Core web app (MVC) then you will have the following structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/0*0jzf8kh3WeWHB2kN" /><figcaption>Project structure</figcaption></figure><p><strong>Step 02</strong></p><p>Update your appsetting.json to store the key-vault URL. Please see sample appsetting.json. You don’t have to use the same way, you can use a simple way that matches your requirement (I prefer to group into sections for readability and maintainability).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/0*1p6FkxMsY6siCozz" /><figcaption>appsetting.json</figcaption></figure><p><strong>Step 03</strong></p><p>Update your CreateHostBulder method in the Program.cs file. Please see the screenshot below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*sgne23cT6x7RgcOS" /><figcaption>Program.cs</figcaption></figure><p>In this step you have to install following dependencies to the project</p><pre>Microsoft.Azure.KeyVault</pre><pre>Microsoft.Azure.Services.AppAuthentication</pre><pre>Microsoft.Extensions.Configuration;</pre><pre>Microsoft.Extensions.Configuration.AzureKeyVault</pre><p><strong>Step 04</strong></p><p>Now as the next step you will have to create an App service and Key-vault to host your application and store your secrets (I’ll publish another article on how to setup App service and the Key-vault).</p><p>For this article I have already created an App service and key-vault. In this section I’ll demonstrate how to set up service principles for the App service and assign it to the Key-vault.</p><p><strong>Step 05</strong></p><p>Go to the app service you have created for the project and select Identity in the left menu.</p><p>Select the system assigned tab in the page and turn on the system assigned identity. Please see the screenshot below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/0*mA2dSNhxyMBAVPzl" /></figure><p><strong>Step 06</strong></p><p>Next go to the Key-vault for the project and open the Access policies page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/0*4Lf4AXIMvOZ2-Or0" /></figure><p>Click on the Create button on the top of the page and you will be redirected to fist step of the policy generation page.</p><p>Select the required permissions for the policy from the permission tab</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/0*HgvsewgCqmRk04t9" /></figure><p>Next select the app service you wanted to connected to the Key-vault</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/0*mDUN8vszhbKlJh4v" /></figure><p>The application tab is an optional one for this demo. I’ll be skipping it. And finally you can create the service principal. Once it completes you can see the Access policy under application group similar to below screenshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1rOOp-DNacCIwEn0" /></figure><p><strong>Step 07</strong></p><p>Before publish the website you have to provide the Key-vault URL in the appsetting.json file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/0*qXcYol-lFIVyxP-e" /></figure><p>Or you can update on your Dev-ops pipeline as well.</p><p>Finally publish your website to the app service.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3abf55f7ef9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>