Programming Tips πŸ’‘
51.7K subscribers
67 photos
10 videos
30 files
354 links
Programming & AI:
Tips πŸ’‘
Articles πŸ“•
Resources πŸ‘Ύ
Design Patterns πŸ’Ž
Software Principles βœ…

πŸ‡³πŸ‡± Contact: @MoienTajik

🎯 Buy ads: https://telega.io/c/ProgrammingTip
Download Telegram
Render Action & Render Partial.png
1 MB
Nancy wants to display the logged-in users in a partial view. πŸ‘€

She got confused whether to use RenderAction or RenderPartial.🧐

Mark clarifies her when to use what. βœ…

γ€°γ€°γ€°γ€°γ€°
#AspMvc
@ProgrammingTip
Use DbContextPooling to Improve the Performance : .NET Core 2.1 Feature πŸ’Ž

If you are familiar with .NET Core, then you might be knowing AddDbContext method. 🧐

This method is used to inject dependency of DbContext into your controller and it should be written in the Startup.cs class. πŸ’‰

So in case of AddDbContext, a new instance will be created for each request and would get disposed once the work is done. ♻️

New contexts are getting created for each request. ⏳

That is still fine but if there are more than 1k requests – 1k times object will be created and disposed, unless you have made it a Singleton. ☝🏻

Creating and disposing of so many objects may impact the performance. ❌

How DbContextPooling can help❓

https://t.iss.one/pgimg/117

[ Article ] : https://bit.do/dbpol

γ€°γ€°γ€°γ€°γ€°γ€°
#AspMvc #Core
@ProgrammingTip
Using MariaDB with ASP.NET Core 2.0 🌊

What is MariaDB❓

MariaDB is a community-developed fork of the MySQL relational database management system intended to remain free under the GNU GPL. 🐧

Development is led by some of the original developers of MySQL, who forked it due to concerns over its acquisition by Oracle Corporation. πŸ’Ž

Basically it is a fork of MySQL which is guaranteed to stay open source, and as noted it is supposed to be a drop-in replacement for MySQL. ✨

So let’s put this to the test with a simple ASP.NET Core application. πŸ”₯

https://t.iss.one/pgimg/118

[ Article ] : bit.do/mariad

γ€°γ€°γ€°γ€°γ€°γ€°
#AspMvc #Core #MariaDB #MySql
@ProgrammingTip
Blazor πŸ”₯

An experimental .NET web framework using C#/Razor and HTML that runs in the browser via WebAssembly that is supported by Microsoft. πŸ’Ž

Blazor is a .NET web framework that runs in any browser. 🌐

Blazor uses only the latest web standards. No plugins or transpilation needed. βœ…

It runs in the browser on a real .NET runtime (Mono) implemented in WebAssembly that executes normal .NET assemblies. ⚑️

It works in older browsers too by falling back to an asm.js based .NET runtime. πŸ‘΄πŸΏ

Blazor will have all the features of a modern web framework, including ✨ :
β€’ Components
β€’ Routing
β€’ Layouts
β€’ Forms and validation
β€’ Dependency injection
β€’ JavaScript interop
β€’ Live reloading
β€’ Server-side rendering
β€’ Full .NET debugging


https://t.iss.one/pgimg/120

[ Github ] : bit.do/blazor
[ Learn ] : learn-blazor.com
[ Flight Finder ] : bit.do/ffinder
[ Sample CRUD ] : bit.do/bzcrud

γ€°γ€°γ€°γ€°γ€°γ€°
#Blazor #AspMvc #Core
@ProgammingTip
Avoid Lazy Loading Entities in ASP.NET Applications πŸ™…πŸ»β€β™‚οΈ

Lazy Loading is an Entity Framework feature that lets you worry less about the specific amount of data you need to fetch with a given query. 😌

Instead, you write simple queries, and Entity Framework will load the minimal amount of data (which is a good thing), and then will only fetch additional data on an as-needed basis. βœ…

That is, rather than eager loading all of the related data a given entity might have, lazy loading is a technique that has EF perform the minimal amount of work needed up front, and then only performs additional work if it turns out to be necessary. ⚠️

This sounds like a great feature, but you should turn it off in your ASP.NET web apps. 🚫

This article explains why you should do this. 🧐


https://t.iss.one/pgimg/121

[ Article ] : bit.do/lazyy

γ€°γ€°γ€°γ€°γ€°γ€°
#AspMvc #LazyLoading
@ProgrammingTip
Programming Tips πŸ’‘
Photo
ASP.NET Core.2 & Angular 5.pdf
7.3 MB
ASP.NET Core 2 & Angular 5 - Full Stack Web Development with .NET Core & Angular πŸ“•

Author : Valerio De Sanctis πŸ–Š

Publisher : Packt πŸ’Ž

γ€°γ€°γ€°γ€°γ€°γ€°
#Book #AspMvc #Core #Angular
@ProgrammingTip
API Feature Folders ⚑️

In ASP.NET Core (and unlike ASP.NET 5 / Web API 2), Web API controllers are just controllers. πŸ—‚

You don’t need to inherit from a different base type or anything like that. ❌

What’s more, your API controllers should be returning DTOs that are separate from your underlying domain or data model. ↔️

What I’ve found to be a better organization is to do away with the Controllers folder (or keep it around if you’re using view-based controllers) and instead use feature folders for your APIs. πŸ’Ž

I’m partial to having a root level API folder but if you’d prefer to put your features in the root of the project that would work, too. πŸ‘πŸ»

Within each feature folder, you include the controller along with any model types it needs to work with, like this πŸ‘Ύ :

https://t.iss.one/pgimg/124

Obviously one benefit of this approach is that it’s more cohesive. βœ…

Things that change together are located physically next to one another, and the friction involved in moving between different folders with too many files in them is greatly reduced. βœ‚οΈ

Another nice thing about this approach is that it just works. Unlike view-based controllers, you don’t need to change anything about how ASP.NET Core is configured to have this organization structure work for you. ✨


[ Article ] : bit.do/apif

γ€°γ€°γ€°γ€°γ€°γ€°
#AspMvc #Core #API
@ProgrammingTip
Favor Privileges over Role Checks ⛔️

A very common practice in web applications, especially those written using the ASP.NET built-in Role provider, is to perform role checks throughout the code to determine whether a user should have access to a particular page or control or command. πŸ”

For instance, you might see something like this ♻️ :

if (User.IsInRole(Roles.Administrators))
{
SomeSpecialControl.Visible = true;
}


The problems with the maintainability of this approach become apparent after a short while.❗️

For one, any buttons or other controls on the SomeSpecialControl above that post back to the page should also do a role check to ensure the user submitting the postback is in an acceptable role, otherwise a security hole may be present and users outside of these roles may be able to perform privileged actions. ☠️

πŸ”ΈπŸ”ΉπŸ”ΈπŸ”Ή

Introducing Privileges βœ…

Wouldn't it be better to act like this❓

EditorPanel.Visibility = CurrentUser.CanEdit(CurrentArticle);


This is very clear and is at the appropriate level of abstraction. πŸ’Ž

CanEdit isn’t itself a privilege; we can look at it as a sort of helper method in this case that lets us write clear and concise code. ✨


https://t.iss.one/pgimg/127

[ Full Article ] : bit.do/prauth

γ€°γ€°γ€°γ€°γ€°γ€°
#AspMvc #Authorization
@ProgrammingTip
Apress - Real-Time Web Application Development.pdf
21.3 MB
Real-Time Web Application Development : With ASP.NET Core, SignalR, Docker, and Azure πŸ“•

Author : Rami Vemula πŸ–Š

Publisher : Apress ✨

γ€°γ€°γ€°γ€°γ€°
#Book #AspMvc #Core #SignalR #Docker #Azure
@ProgrammingTip
Using Redis Cache in .NET Core πŸ—‚

Redis is a high performance distributed cache. It’s great for storing data that you are going to need again and again in a short period of time when you don’t want to use processing power to β€œcreate” that data again. ♻️

Think number crunching or heavy SQL queries for data that doesn’t change often. 🚫


Roll Your Own πŸ‘€

First off. You can absolutely roll your own Redis Cache services abstracted by your own interfaces etc. βœ…

You may find it a little difficult to find libraries that target .NET Core, but this will change over time. ⏳

In saying that, there is a β€œ.NET Core” way of doing things that is a little different. It does tie you into the framework a little, but it abstracts away the caching completely and let’s Microsoft handle it and that’s what we are going to go over today. πŸ’Ž


https://t.iss.one/pgimg/131

[ Article ] : bit.do/rcache

γ€°γ€°γ€°γ€°γ€°γ€°
#Redis #AspMvc #Core #Cache
@ProgrammingTip