Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
448 views
in Technique[技术] by (71.8m points)

.net - System.Web.Abstractions: what is it good for?

... absolutely nothing?

What part of the puzzle does it fill for ASP.NET WebForms and ASP.NET MVC respectively?

Can you somehow create a ASP.NET * base-application which uses System.Web.Abstractions so it can be used in both kinds of ASP.NET-web applications?

In that case, how did they retro-fit the classes in System.Web.Abstractions back into ASP.NET WebForms?

You can't new up objects from the namespace, so it can't be used for mocking, can it?

Update: Sorry for not being clear on that I know the problem with testing of HttpContext and other build-it ASP.NET-objects. But thanks for good explanations anyway.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The namespace contains types that are designed to wrap ASP.NET's core classes (such as HttpSessionState).

What, you want to know why?

Many of these core ASP.NET classes are sealed or static, making it impossible to break dependencies between them and your code. THAT means you can't mock these core dependencies, making it much harder to test your ASP.NET code. So, instead of directly manipulating the HttpResponse directly in code, you manipulate it via the HttpResponseWrapper, which, during test time, you can stub or mock out to control how the HttpResponse object behaves.

If you've ever thought about creating these wrappers, or have implemented one or two of them before, you'd know that there's lots of work wrapped up in that namespace, and I, for one, am glad they did it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...