Today I Learnt (TIL)

This is where I stash a quick note of things I learn as I learn - it is important as I tend to forget quick wins from long reads / videos.

  • #17

    OpenID Claims mapping

    18 June 2024

    When adding OpenID-based authentication to ASP.NET Core’s Authentication pipeline, the module will try mapping the claims from the external party to Identity entities and claims. This leads to misleading claims appearing in the object, according to this excellent video

        builder.Services.AddAuthentication("cookie", option =>{
            //...
        })
        .AddOpenIDConnect("oidc", options => {
            //...
            //...
    
            options.MapInboundClaims = false; //prevents conversion of raw claims to identity claims
        })
  • #16

    .NET can prebuild front end

    9 June 2024

    I learnt while setting up build process for Jester that you can add a bit of config in .csproj to tell .NET to precompile front end before compiling other targets such as Build.

    I added the following

      <Target Name="BuildFrontend" BeforeTargets="Build">
    	<Exec WorkingDirectory="$(ProjectDir)UI" Command="npm run build" />
      </Target>
  • #15

    The true meaning of a repository and a service

    3 May 2024

    As part of builder Jester, I have been pondering whether to implement data services. One of the key objectives I had to this was that I needed to have an intuitive understanding of why this is a natural need in building enterprise apps.

    When I found that the first advantage was being able to unit test a lot better, I came to accept introducing it. Then I found out I need a repository to sit between the service and the database. I have heard a few whistle about service being for business logic, and repository being for database transactions. In my head, I already heard business logic as a reason for many other separation of files (remember role of view models?) so this was just not going to cut it.

    Anyway, I did more digging and reading before it final set in what the meaning was. Here’s what I understood and shall be my understanding going forth:

    A repository handles the data access and the service calls into it after performing any business logic needed.

    Link to source and the answer that will have also been sufficient but undoubtedly aided in beautifying the one we have highlighted.

    A repository - what does it mean?

    A repository contains methods that may or may not be complex, but entirely tied to interacting with the database. Each transaction results in an interaction with the database. It exposes for example CRUD methods, and hides how it interacts with the database and what even the database is.

    At one point in time, it may be speaking to a SQL Server over SQL, or at another point, speaking to a NoSQL via an ORM. It does not contain anything that has nothing to do with the DB.

    A service - what does it mean?

    A service contains (business) logic which may or may not use a combination of methods exposed by a repository to resolve a business need.

    For example: it may use the Get method of a repository to get a list of data, then use business-specific logic to filter and match with a business requirement, then use the Update method of the repository to make some updates required by the business.

    What about a data context?

    Yes, this was a genuine question of mine. The answer is essentially made clear by the following two points:

    • The data context is responsible for defining entity sets (tables), relationships, and configuring the database connection
    • It also manages migrations and database schema changes
  • #14

    The best tutorials are not titled

    2 May 2024

    Alhamdulillah, I just found out the best playlist to aid me in covering a lot of ground with the fundamentals of .NET. I had just learnt the history of .NET and Microsoft itself, and was aiming to write a full project unaided sometime in the next few days.

    I was looking to find some podcasts that can introduce terminology and advice passively while I do other things, and just encourage to be a better dev. Through my search, taste and exploration of podcasts and their guests, I landed on this Dev SuperPowers .NET Core Tour and I consider it to be the best - it helps remove confusion from .NET as a framework and gives a clear picture of how things connect and why they are needed anyway.

    Which podcasts led to this and how? .NET Rocks. I searched them up on YouTube and was hoping to see if they have live recordings. And as they say, the rest is history.

  • #13

    The History of .NET

    1 May 2024

    Who knew?

    • Microsoft only rose because of IBM
    • Microsoft almost broke apart
    • C# wouldn’t exist if it weren’t for Sun Microsystems
    • .NET wouldn’t exist if it weren’t for an enthusiastic graduate spending his holiday overworking

    The History of .NET by Richard Campbell of .NET Rocks!

  • #12

    Buying is easier than building

    30 April 2024

    I am an idealist, always optimistic for the greatest benefit. However, reality is the challenge between idea and achievement. One of those things I always wondered was: why can’t we offer services using newer languages (e.g. GO) and to broader industries? I always assumed an answer - that it is a hassle convincing stakeholders to let engineers indulge in new areas of technology.

    However, the answer is more to the tune of “easier to buy than to build”. Why? To offer new high quality services, you need a lot more than just capable engineers. You need everyone that is typically involved in a project from bids, business analysis, sales, service support and all the way to the Dev team to know and be well-acquainted with the new language and service to guarantee reasonable delivery, maintenance and accurate estimation. It is a big risk, and a heavy investment.

    This is the conversation I went into accidentally this morning with my senior.

    It is easier to buy than to build one. You buy expertise, team work, knowledge, reputation, client list, history and confidence. It is not easy to build without significant investment, which most businesses can’t afford. That’s why you’d find businesses acquiring other smaller businesses to grow their service offerings.

    Also explains why businesses would rather outsource to agencies and consultancies over in-house!

  • #11

    A time when devtools fixed problems

    29 April 2024

    I had a bug where opening safari devtools seemingly fixed it. I shared the observation with my team, and learnt there was such a time when IE didn’t support console.log unless devtools was open. This meant you will find your site throw up an error, then you open up devtools to find the error isn’t there any more

  • #10

    ASP.NET stands for ...

    22 April 2024

    ASP = Active Server Pages

  • #9

    This (JS)

    14 March 2024

    I was just bitten by this, after a long time.

    Here’s a note to remind me to be on the watch especially in the case of binding functions.

    My mistake … ?

    import Security from "security";
    
    class Watchman {
        constructor (...props){
            const security = new Security({callback: this.watch})  //!!!
        }
    
        function watch(){
            this.start();
        }
    
        function start(){
            //... duty begins
        }
    }

    The this reference inside watch will no longer refer to this instance of Watchman by the time it is accessed by Security. The solution is of course, to bind this to the watch function before passing it forward. However, the issue at hand is the ease by which you can make the mistake. Need to keep up my guard 😄

  • #8

    Best C# resource

    13 March 2024

    Was just doing a quick recap of C# to see if anything changed, and recall old things. Found this as the best resource C# for Beginners

  • #7

    Typography

    8 March 2024

    Learnt some things to consider regarding fonts, and typography overall:

    • Font vs typeface i.e font != typeface
    • Sans vs sans-serif
    • px vs em
    • Hierarchy of elements (900 - 100)
    • Line-height closer to 1.5
    • Increase line-height for thick fonts
    • Increase line-height when fonts are a dark color
    • Increase line-height for long-form content
    • Use modular scale
  • #6

    .NET BE Architecture

    6 March 2024

    Parts of .NET I should care about:

    • Templating
    • Routing
    • Databases, and repositories
    • Frameworks (Entity Framework etc)
    • Dependency Injection (and other design patterns)
    • Garbage collection
    • Code First Migration

    I was checking the roadmap.sh to collate a path towards conquering the second half of web dev via .NET - although I am already comfortable with JS backends!

    To my surprise, I found that I don’t have to worry as much as I used to. I had been assuming or worrying that I will need to inherit the whole bunch of the .net ecosystem but Alhamdulillah, that isn’t the case.

    I narrowed it down to what matters: building websites. The scope of things to know quickly narrowed down and became easy to understand and learn. I have never learnt and felt as happy learning .NET as now.

    It boils down to:

    • Setting up project and 3rd parties e.g. DI, auth, routing, logging etc
    • Creating models, controllers / view models, and views (which I already know)
    • Interacting with databases via abstractions and frameworks
    • Setting pages and API endpoints
    • Applying fundamentals including MVC / MVVM, DRY, clean separation etc
    • Using appropriate packages to reduce labour of writing code / reinventing the wheel

    I don’t need to worry about queues, streams, events, deployments, polling, and other specialised things yet - their time will come in the future.

  • #5

    Practice vs practise

    6 March 2024

    The trick to using this correctly is by viewing it from the lenses of the type of word it is - noun vs verb.

    • The version with c is a noun
    • The version with s is a verb

    How can you tell or remember? Compare it to other words.

    1. Advice vs advise
    2. Device vs devise

    These 2 simple examples do it for me, especially the second one!

  • #4

    Quick .NET wisdom

    3 March 2024
    • .NET doesn’t make it easy to write plain package-less applications, it gets big too quick. That’s why packages should be used when appropriate, it is the difference between 100 lines and and 5 or 10 odd decorators.

    • Reminded that Software Dev is not all about coding

    • It is not the job of business people to make requirements clear. We should listen, pay attention and analyse to understand problem domain. The solution will then be apparent, it may or may not need code

    • Software architecture is not just for experts. It is about knowing a map of the overall system enough to go wherever you want, and not detailed enough that you will not know your way out

    Source: Avoid These Common Mistakes Junior Developers Make!

  • #3

    Classes can be used as a type

    3 March 2024

    Typescript classes can be used as a type.

    //Example
    
    class Table {
        constructor(){
    
        }
    
        private method(){
    
        }
    }
    
    const table: Table = new Table();
  • #2

    MVVM and MVC

    2 March 2024

    MVC: Model, View, Controller

    • Model handles talking to database, transforming data and exposing ways to work with the data
    • Controller listens to messages (events, actions, requests) from the view and tells the model what data it needs, what needs to be done, and then pass that back to the view, or handle errors and fallback
    • View gets data from controller, uses it to determine what parts of UI should be shown or hidden, and what info from the data should be shown, and what actions need to be attached etc

    Source: MVC Explained in 4 Minutes

    MVVM: Model, View, ViewModel

    The same as above except VM is the controller / the one handling business logic.

    [NOTE: I need to double check ]

  • #1

    VS vs VS Code

    2 March 2024

    VS Code is a text editor and VS [insert release year] is an IDE.

    Where you have to find, install and curate VS Code as you grow wit it, VS 2022 comes with everything you need and beyond at once. One of the reasons why I view VS as being heavy, and VS Code as being light.

    Source: Microsoft FINALLY killed it

Nuh © 2024