#pragma once #include "MiddleWare.h" #include "Request.h" #include "Response.h" #include namespace VWeb { class MiddleWareHandler { public: PreMiddleWareReturn HandlePre(Ref &); void HandlePost(Ref &, Ref &); void Shutdown(Ref &, Ref &); public: template Ref GetRef() { return GetById(typeid(T).name()); } template T &Get() { return static_cast(*GetById(typeid(T).name())); } template void Set(Ref &instance) { auto &type = typeid(T); if (type.before(typeid(MiddleWare))) SetById(type.name(), instance); } template T &Create() { return static_cast(*CreateMiddleWare()); } template void Remove() { RemoveById(typeid(T).name()); } protected: template Ref CreateMiddleWare() { return SetById(typeid(T).name(), CreateRef()); } Ref GetById(const char *id); Ref SetById(const char *id, const Ref &); void RemoveById(const char *id); std::map> m_MiddleWares; }; } // namespace VWeb