-1

I'm working on a Nuget library which can be used for web applications (WebForms, MVC, CORE) and will be published for both .NetFramework and .NetStandard.

In my library I need to access the HttpContext for reading the Request and also for redirecting and writing in the Response object.

What's the best way to have a common HttpContext for all three frameworks WebForms, MVC and CORE?

Note that Microsoft.Owin is not compatible with .NetStandard and also in WebForms and MVC there is a System.Web.HttpContextBase class which is completely different in .NETCore projects and there we have Microsoft.AspNetCore.Http.HttpContext.

D.Raphael
  • 1
  • 1

1 Answers1

0

Your library could be organized this way:

  1. Define adapter interfaces (over HTTP context and etc) in shared source project
  2. Define implementations of all those interface in concreate Core or Classic project - create both. There you should have 3 projects in your solution.
  3. Now your library is 4th project it should be multitarget, use conditional symbols to enable or disable "Classic" or "Core" adapters. Use adapters to access "Http Context and etc".
Roman Pokrovskij
  • 9,449
  • 21
  • 87
  • 142
  • Actually, Interface was my first solution. But I didn't want to reinvent the HttpContext class because I need bunch of methods and properties in both Request and Response objects. – D.Raphael Feb 07 '19 at 13:00