- Middleware, ASP.NET Core seviyesinde çalışır ve uygulamaya gelen her request üzerinde işlem yapabilir.
- MVC filters ise yalnızca MVC'ye gelen requestler için çalışır. (eg:
ModelState
orIActionResults
) - Middleware, HttpContext gibi daha düşük düzeyli soyutlamalar üzerinde çalışan daha genel bir kavramdır.Onun için uygulamaya gelem tüm requestlere uygulanmasını istiyorsak Middleware, Controller yada action bazlı olmasını istiyorsak Filters kullanmalıyız.
In ASP.NET Core, middleware and filters are both used to implement cross-cutting concerns that affect multiple requests in an application. While they have some similarities, there are also some key differences between them.
Middleware is a software component that is executed between the web server and the application. It intercepts incoming HTTP requests and outgoing responses, and can perform a wide variety of tasks such as authentication, logging, and exception handling. Middleware is implemented as a chain, with each middleware component in the chain responsible for processing the request and passing it on to the next component in the chain.
Filters, on the other hand, are used to implement cross-cutting concerns that are specific to an action or a controller. Filters are executed before or after an action is executed, and can perform tasks such as authorization, validation, and caching. Filters are implemented as attributes that can be applied to actions or controllers, and can be global, controller-level, or action-level.
Here are some key differences between middleware and filters:
Middleware is executed for every request, while filters are executed only for the actions or controllers that they are applied to.
Middleware operates on the entire request and response, while filters operate on specific actions or controllers.
Middleware can be implemented as a pipeline, with each middleware component in the pipeline responsible for processing the request and passing it on to the next component. Filters, on the other hand, are not part of a pipeline.
Middleware can be used to implement a wide range of cross-cutting concerns, while filters are generally used for concerns that are specific to an action or a controller.
In summary, middleware and filters both provide ways to implement cross-cutting concerns in an ASP.NET Core application, but they have different scopes and are used for different purposes
Hiç yorum yok:
Yorum Gönder