In/Out Middleware Explained (C# ASP.NET Core & JS Examples)
HTML-код
- Опубликовано: 21 сен 2024
- In this middleware tutorial I answer questions like: what is middleware? how does middleware work? how to implement middleware? We implement our own middleware pipeline in C# & Javascript, and also take a look at how middleware works in asp.net core & the HttpClient as well as looking at the Interceptors in axios and angular. Remember it's just a function wrapped in another function, being able to write a neat implementation is just a scalability problem.
Patreon 🤝 / raw_coding
Courses 📚 learning.raw-c...
Shop 🛒 shop.raw-codin...
Discord 💬 / discord
Twitter 📣 / anton_t0shik
Twitch 🎥 / raw_coding
👉 Try Rider
www.jetbrains....
RD5K9-4TXXW-KMV3G-NYWSF-3ZSTP
LinqPad: www.linqpad.net
Source: github.com/T0s...
#csharp
i always looking for in depth tutorials with good presentation, unfortunately there are not many channels capable of producing them, but you my friend are from the gifted few!
it feels like getting free lessons from jesus (un-related to your beared :D )
keep up the good work, god bless you
Hahaha thank you man :) glad you like these :)
@@RawCoding Thank you Jesus.. You are the Savior! Namaste from Hyderabad, India!
Anton,Thank you for the content you create, I have gone thru lot of channels and end up with the default content available everywhere, but you sir have taken explaining things to another level. Now this is what it means to share knowledge. 🙏🏼🙏🏼🙏🏼
Thank you Rajkiran
I pray to Jesus every day and now I am learning coding with coding Jesus, I know I'm blessed. Thank you, Aton,will watch all your videos and code with you!
I am going through all the videos from your playlist every morning before starting my work.
Making it a habit to watch atleast one video everyday and learn something new
Glad you’re enjoying these!
@@RawCoding Can you also make a playlist for Azure 204?
No
One of the best programming vids I've seen in a while :)
Cheers
hands down the best video on middlewares
Thank you )
Incredibly useful to see the own implementation and then the variety of ways it can be added to VS solution in practice.
Glad you liked it, don't forget to like and sub
@@RawCoding Anton where are you from? Do you have any social media like twitter acc?
@@oz5277 I'm from Latvia buddy, and all my video descriptions are full of links to my social media )
@@RawCoding Sorry, my bad. Thanks!
Yesterday I wanted to start the discovering of the specific Middleware concept in details, and it's amazing that you provided the video immediately for the subject. Thanks a lot!
Just in time! Thank you for watching)
I believe it was a little bit confusing to say "we use type called Action, and nobody uses delegates anymore", while what was called "type Action" is just a delegate (which is an actual type) provided from .net libraries in advance
Thank you for pointing out
I thank youtube for suggesting this video. For me this was not just a refresher to middleware. Mind blown 🙌
Thanks Gilfoyle 😊 ..Thanks for broadining my horizon 👍
Gilfoyle? :D
@@RawCoding From the tv show Sillicon Valley. I thought I recognized you from somewhere. Great stuff man! This channel should boil Dinesh's brain for a while. :D
Ah alright)
You are awesome, thank you for everything you have thought me so far. You really are talented. You set a whole new standard
Cheers :) glad you enjoyed the content
Loved the way how you explain something about programming principles! More knowledge, greater yourself will be. Thank you so much!
Thank you)
@@RawCoding one last thing, dude. I would like to request to explain further the middle-out compression made by Richard Hendricks of Silicon Valley from the beggining he developed it up to the optimization he made on the day before their final appearance (last episode of season 1, I think).
I'll be more grateful if you grant my request!!! :)
What?
I'm a bit late to the game, but I just want to say that your videos are amazing. Thanks a ton for creating them! The explanations are always in-depth but clear and concise.
Never too late, these concepts aren’t going anywhere
Amazing !!! Can you please do a tutorial on Events,reflection,Modern design patterns etc..
I don’t use events, I can teach some design patterns.
Great content. Loved it. Learnt bunch of new concepts. I will watch more and more of your videos. Thanks again sir 🙏🏼🙏🏼🙏🏼
Great stuff. brilliant examples. great 👏👏. keep going..
Thanks :)
You have been sharing wonderful knowledge, Thank you somuch! I would like to listen about Generics- Contra, Covariance.. and how can we visualize a business scenario to implement Contra, Covariance.. thanks!
Cheers, will take a look at this topic at some point
Thank you for your great videos! I'll watch asap:)
Cheers)
You are such a great educator thank you hope you create an asp.core fundamentals for beginners and thank you
I’ll take a look at that :)
I like your videos, they are different. Sometimes, I feel like you are going faster than I can track .I will have to slow you down at 0.75 and you sound like you are under the influence :)
Haha high on life!
Very good videos and explanations of some of the most complex topics. Most of the videos address the What, why, how aspects of the topics. A rare feet to achieve !! kudos...
Please also provide some videos on internal implementation of threads and processors in the context of multi threading.
Cheers, yeah the thread implementation is beyond me this is something managed by each individual operating system from what I know.
@@RawCoding In context of windows and .net ;)
I’ll do it if I have time, I’ve never needed to know the implementation to use them :)
Awesome, much helpful. Thanks for the video :)
Thank you for watching!
this is liquid gold
Cheers
Who are you man?, you are just amazing...
Really good explanation. Thank you!
explain clearly,thanks for your work
Very well explained, thank you
These is Gold. My advice is to try and code yourself what author is planning to do and than listen how he will do it. You will understand X10 better. Passive ;listening did not worked for me.
Spot on!
@RawCoding Your content is fantastic! Thank you for your exceptionally easy to understand videos. I know from experience that making advanced concepts as digestible as you do is remarkably difficult and time consuming. So I wanted to say thank you.
Thank you for your comment! Really appreciate it
as always - good to understend! thx!
Thanks for watching :)
If you go to definition of Action and all it’s overloads they are just delegates behind the scenes. Delegates never actually went away
There’s no problem that can’t be solved with a bit of indirection amaright
This is very interesting ! Side question : which font do you use to have the lambda displayed as a nice arrow and not => ?
thanks for this video. i found that educational. one thing i'm not exactly following is this. at the end var pipe kinda hides what the pipe type is. build method returns a single action looks like. when we build we seemingly return a collection of actions not just one. what is pipe if its its a collection of actions of type Action? how are they all nested inside a single Action?
if you can put an object inside another object, you can put a function inside another function. You can keep putting things inside other things and on the surface it will still look like 1 thing
This is beautifully explained. I am a salesforce developer and I have always been thinking of building a library/ framework for handling Inbound Http requests in a fashion similar to how dotnet does it. However Apex doesnt support full scoped reflection (even though we can instantiate dynamically) , functional programming, lambdas and even generics (although this is in the works). Is there a purely object oriented way of achieving this type of middleware configuration ? Something tells me its possible but I wanna know what you or any other expert thinks. THanks in advance
Looks like a twisted 'Chain of Responsibilty' design pattern implementation.
I gues you can say that :)
what you are explaining in this video it seems to me a decorator pattern.. anyway great video so far on RUclips related to .NET middleware
How the internals of the middleware look like. Decorator or function composition, whichever you prefer.
@@RawCoding one more thing i need to ask as you explain decorator or function composition can we relate this to MediatR pipeline or
MediaR using different strategy ?
Mediatr pipeline has same strategy
Well explained..
thanks , excellent
There is no Dump method in .NET; I would suggest to either use online c# compiler or mentioned the DUMP is exist only in
LinqPad .
yeah Dump is LinqPad ONLY
For such raw or depth coding from which book did you learn
Dude, really cool stuff!
Thank you)
Probably a silly question, but what is the difference between the Middleware and Decorator Patterns?
Middleware is more of a chain of responsibility, decorator is about giving an object an ability to do something, where’s here we are defining a process for handling something
Thanks a lot. Great content.
best respect for you ... from Viet Nam ^^
Thank you)
Why do we use Action instead of the delegate ? Isn't Action underneath a simple void delegate ? Is it faster or just smarter and quicker because of the syntactic sugar ?
Action is a delegate underneath, we use action because it’s a prebuilt thing that in the end of writing out 1000’s of delegates we would arrive at Func and Action our selfs, it’s a nice abstraction, kind of like the DbContext for repository pattern in efcore
@@RawCoding Thank you for the answer. Great channel. I hope you are doing well around this scenario and keep grinding :) Cheers Raw!
Cheers ) all is well
Now I get it. The C in C# is for Carpentry. Seeing Jesus coding in C# makes it clear.
Спасибо! Очень доступно объясняешь)
Спасибо за просмотр)
Awesome video! The are plenty of low level programming videos, but u provide us with deep concepts. Do u offer mentoring?
Cheers from Germany ;)
Cheers, I do on patreon however I think all slots are taken ))
Hello!
This behavior can be achieved by a chain of static methods.
Try (). Wrap () .... First ()
Or I do not understand why the concept of pipes is needed?
It’s try > wrap > first > wrap > try ; rather than chaining
@@RawCoding Got it! Thank! Very handy thing!
Do you have a c# course? If not, please consider doing a c#8 tutorial.
I am working on a c# course :) I've not got too much time to make it thought so It's coming along slowly
Seccond function has two c's because it's second, rright?
I guess can’t remember)
Anton, what's progress of your C# course?
We are waiting for your amazing course on C#🙏
It’s not done
Thank you for the quick reply. Hope it gets live sometime soon 👍🙏
Yeah it’s not going to be soon :D working hard on it though
@@RawCoding ok no problem 😊
Can you please do a tutorial with clean architecture and some DDD patterns :)
Maybe:)
Thanks for this great Tutorial, again.
This is quite difficult to understand at first because there are no variables to hold those Pipe instances constructed at the each call of CreatePipe() method.
As for me, it looks like losing instance reference so very weird and hardly understandable. :(
Actually, to store those instance references, I tried changing List to List but it wouldn't allow chaining Handles in order of calls of AddPipe() methods.
Is there any terminology referring to the way you used to grab the method reference of instance (but fly away the instance reference)?
Method reference is a function pointer
@@RawCoding Well. It seems like hooking a fish on its side not its mouth. ^^
really appreciate your content, fantastic work. Do you have a plan to do video on asp.net model binding??
Mmmm can do
@@RawCoding thanks
Awesome I like linqpad 👍😎
Me too)
This could be done in more easy and less code way
public class Pipeline
{
public void Use(Func middleware)
{
_actions.Add(middleware);
}
public void Run(Func middleware)
{
_actions.Add((context, next) => { return middleware(context); });
}
public void Handle(Context context)
{
var it = _actions.GetEnumerator();
Handle(it, context).Wait();
}
private Task Handle(List.Enumerator enumerator, Context context)
{
if (enumerator.MoveNext())
{
return enumerator.Current(context, () => Handle(enumerator, context));
}
return Task.CompletedTask;
}
private List _actions = new List();
}
Thank you for sharing
@@RawCoding No problem, it just happened that I recentley tried to work out how to build such a middleware pipline for processing anything in a middleware chain fashion. The challenge was how to convert list of middleware callbacks into nested functions call. Recursion was the answer and I drafted the presented solution. It could be further extended to cover class middleware and other different use cases.
👍🏽
)
I subscribed 😀
public PipeBuilder AddPipe(Type pipeType){
if (!pipeType.GetTypeInfo().IsSubclassOf(typeof(Pipe)))
{
throw new Exception();
}
_pipeTypes.Add(pipeType);
return this;
}
Ahha! Thank you ))
Why don't you create a playlist on ASP.NET MVC (every version should be fine, 5 or Core)?
I don't use ASP.NET MVC, it'll only be .Net Core & .Net 5 moving forward
Who would've thought I'd be learning C# from Jesus himself.
How can you return void? That doesn’t make sense. Void means no return value.
Where does that happen?
I want to code along with, which editor you are using?
LinqPad but you can use VisualStudio or Ride or VS Code
Thanks a lot for tutorial! There is no more Jesus style ((
Actually havn't any doubt about your skill..but things got little bit hard for us ..pls try to break into some portion and explain with some appropriate example
How do u learn those concepts? is in some books????
Google, a lot and then practice
@@RawCoding cool man. Keep doing videos about #AdvancedCoding. i need your help with videos like this. Thanks a lot
Cheers ))
Good video.. Can you make a video on Covariance and Contravariance in C#
Cheers, and I’ve never heated of that before so no :D
I beg your pardon. But my guess, you're tryna say "crunch" amaright?
Where?
@@RawCoding 10:27
Crutch - when you brake your leg you gotta use it to help you walk.
@@RawCoding Thanks for sparing time and for great content.
Thank you for watching )
очишуительно.
a to ))
Is this suppose to be for developers or people who wants to be developers?
I was able to follow for like 1/3 of the video, half way throught is only mumbo jumbo left in my head, function in functions in pipelines in pipelines with list of pipetypes and activators.
You are going way to fast by the way.
For this kind of topic some visual presentation is a must IMO.
Video is probably good and im just a moron, i dont know.
Are you people understnd whole video perfectly?
Maybe i should drop programming, im trying to go all the way with this, but it seems to be perfectly understandable for everyone so i dont see how im suppose to compete for job when im not able to follow and understand this .
Hi there don’t be discouraged, this is not a beginner topic so I guess it’s for developers who are trying to deepen their knowledge, this is for those who have been or are about to use middleware but never really understood how it worked.
@@RawCoding Thanks but the problem is im not such a beginner, ive used middleware before couple times and i begin to learn like year ago.
First i learned C# then html, css,ASP, bootstrap, unit testing, SQL, now im going back to finish my application and wanted to refresh some most important topics, and i dont even clearly remeber how delegates work.
Amount of knowledge for becoming .NET dev is so massive, if i had 2 brains it wouldnt be enough, and i probably would have to watch this video 7 times to get all of this on some decent level.
Sorry for bitching , i probably need another year to be decent candidate and it makes me depressed, i thought it will be enough to just put enough time but thats not true, brain capability and memory are most important things, math is imortant too becouse theres algorithm tasks on interviews and im beyond terrible at math adn dont even grasp that yet.
Now im pissed becouse i came to conclusion this its not for me but im too far gone to just drop it, i will not but the end of story will be that after series of job rejections i will loose all confidence and wont even be able to step through the door for another one.
Ey man just notice that your head is in a negative space and you are putting your self down for no reason. Instead of focusing on how bad you are at something try to understand it and take it slow.
A function represent some kind of work we want to do an action or a ‘doing’
A delegate is just a way to represent a function signature (parameters and return type) under a name
Middleware is the ability to put a ‘doing’ (or a function) inside another ‘doing’
You don’t need to know C# syntax to understand that you are just nesting/wrapping some actions/functions/doings inside each other. Imagine you were making tea and in the middle of that process you decided to make a sandwich, vuala middleware
Don’t be too hard on yourself this stuff is hard, I recommend join the discord server, you can get further help there :)
@@RawCoding This is as much as i understood, but im lost any further, im watching second time now and its clearer now, if i wouldnt know what function is after a year you should assume mental illness and be suggesting to drop it for my own good:).
Im not puting myself down actually, my mind is, i didnt decide to start producing bullshit thoughts in my head, just happens i have to listen to them, but unfortunetly they mostly right. Theres like 1% junior offers, u have to be full stack, no more backend frontrend, golden years are gone in my country, expectations are going higher and higher and now corona adding to the bullshit. I would not start from zero if i had the choice again
, seems pretty ridicolous. I spoke to a friend today, after 80 hour of courses of dieting and workout hes ready to be personal trainer, meanwhile after 1000 hours of learning i have troube understanding a tutorial.
I work hard on this sometimes all day long but i learn as slow as u can get, unfortunetely nobody give a shit how hard u worked.
I think it’s generally not being comfortable with functions as a thing and how to compose them which can cause a lot of confusion in understanding this topic.
eNtErPrIzE software: spend 20 hours to save 5 seconds of typing.
Also make your code run 100x slower. Can't have customers with a good user experience, no sir.
It's like being taught by the Jesus
Be blessed 💦
Can you translate in arbik
No
@@RawCoding that's bad don't wery thank you