views:

137

answers:

3

Maybe a strange question, but where would you put HttpHandler classes in a n-tier architecture? I have a service layer, a domain model layer and a data layer. Should I create a separate class library for the HttpHandlers?

+2  A: 

These are my preferences:

You're reusing the IHttpHandler across sites as you mentioned so its own separate library would be my preferred project for it.

Of course if it's the only class in the library then that's complete overkill. You've also said it needs access your domain and data. You can keep these internal and use:

[assembly: InternalsVisibleTo("MyHandlerLibrary")]

That goes in the Assemblyinfo.cs file (or wherever you're storing the assembly information) of your Domain library.

I wouldn't want to be an architectural astronaut for the sake of it though. If you know your Handler isn't going for global domination, be happy sticking it in the service class library.

Chris S
Problem is that there are a couple of sites that will use the same HttpHandler... So there's not one MyNamespace.Site.
Lieven Cardoen
And it does indeed need internal aspects of the core.
Lieven Cardoen
I'll update the answer
Chris S
+3  A: 

My opinion: I would put them in the service layer, perhaps in a subfolder of that project.

Greg
+1  A: 

HTTP Handlers are technology - they can be used to expose an interface (of sorts) anywhere you want. The important question is what's the purpose of the services? Are they 'technical' services or 'business' ones?

If you can answer those questions you'll be closer to working out where they need to go.

It's also important to remember that they are exposed as part of a web-based application (or component); if you want to expose something over the web then they can be a good option. So if you wanted to expose your data access via the web then yes you could use HTTP Handlers.

Should you recreate a seperate library? if the interface exposed by the HTTP Handlers is generic (say logging) then you could, although it's more likely you'll have some 'helper' methods in a library, and your 'service' specific HTTP Handlers will be where you need them.

Adrian K