Guest User

Untitled

a guest
May 23rd, 2025
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. interface IMyContext
  2. {
  3.     string UserIP {get;}
  4.     string UserAgent {get;}
  5. }
  6.  
  7. interface IMyContextInitializer
  8. {
  9.     void Init(string userIP, string userAgent);
  10. }
  11.  
  12. class MyContext: IMyContext, IMyContextInitializer
  13. {
  14.     ...
  15. }
  16.  
  17. // на стерте где инициализируешь DI, добавляешь
  18. var ctx = new MyContext();
  19. RegisterScoped<IMyContext>(ctx);
  20. RegisterScoped<IMyContextInitializer>(ctx);
  21.  
  22. // дельше пишешь свою midleware, где запрашиваешь IMyContextInitializer и через Init присваиваешь значения
  23.  
  24. // потом просто инжектишь IMyContext где надо
  25.  
Advertisement
Add Comment
Please, Sign In to add comment