Introduction to AOP in C#

preview_player
Показать описание
In this session, I'm going to show you how you can leverage DispatchProxy in C# to implement AOP.

This capability will allow you to add layers or aspects on top of your existing implementation of the functionality of any routine without polluting your business logic code with side-routines like tracing and logging.

Here's some useful links:
Demo Code:

DispatchProxy in .NET Core Blog:
Рекомендации по теме
Комментарии
Автор

This is absolutely useful, thank you!

dotnetMasterCSharp
Автор

awesome my prof, we need more thanks a lot for this Chanel

ahmedelgendy
Автор

Great never done it this way but will keep this in my knowledge bank. I have always used something like autofac and interceptors to achieve this kind of implementation.

jwcodendaal
Автор

Wow thank you so much, this changed MY LIFE!! amazing.

linguini
Автор

Nice. Next time, show us the performance implications of using DispatchProxy vs. not using it. I'll implement this myself but it would've been nice to see here also.

ParkImaging
Автор

This video is supper intersting and an amazing

iam_ali_muhammad
Автор

A minor correction on `unmanaged`, it's all primitive types and user-defined types that only use other unmanaged types, including other user-defined types. It's basically a way to say "this doesn't use managed memory objects like `ref` fields or reference types (classes, interfaces).

AlFasGD
Автор

Thanks a lot, Now I can customise my aspnet core middleware.

MihaiMoisei
Автор

Awesome, always wondered how the magic behind EF lazy loading proxies works.

tedchirvasiu
Автор

Yeah, that's great. It triggered my inspiration. Thanks for the video.

DasturlashniOrganamiz
Автор

Let's not forget the Attributes in C# that are a good implementation of AOP, and have been there forever.

PierreH
Автор

I am reminded of interception via decorator pattern.

aaryavartsolutions
Автор

A ready-made implementation of the proxy pattern?)
Is also not generic. This may not be good for performance.

I'm talking about boxing for passing arguments to Invoke.
Same with the return value.
It will be very sad to call the proxy method in a loop for a large number of values)

zadrot
Автор

This is golden! This can be useful in a nuget package that I am writing! However can this be unit tested?

sunnypatel
Автор

Personally I'd avoid using such kind of implementation for any serious development where performance matters. Probably a good evolution in this field for C# could be given by source generator, I'm wondering if there is already any source generator that implements decorator patterns, could be an interesting project to play with

FabioAngela
Автор

Hi Hasan
Thank you for the video. Is it possible to wrap a class with multiple proxies? Let's say, in your example, if you wanted two interceptors, one for logging and another to inspect the parameters and omit any PII information. Would the two proxies wrap the IStudentService OR one would wrap the IStudentService and another would wrap this Proxy instead of IStudentService? (Later would be like Proxy of Proxy)

zfold
Автор

Can be a good way for benchmarking, but I think maybe reflection would lead to inaccurate result as reflection is slow. Is it so ?

bilalhussain
Автор

how do you inject a service into another service? Like, if I have a service calling a API but I need to get the API key from a database?

Автор

Appears this method does not support recursive functions. Only top-level calls are intercepted. Is this true, or I'm missing something?

asyrovprog
Автор

can this be used to guard certain methods with requireing permissions?

garcipat