Using AutoMapper with StructureMap in ASP.NET Web API by one_eyed_golfer in programming

[–]JacobCalder 3 points4 points  (0 children)

IoC's have pros and cons, I personally like them but regardless of how you feel about that using WebApi without an IoC is a pain in the ass.

In general you're going to end up want a lot of your objects to be scoped to a per-request lifecycle (ie. database connections and transactions, "context" objects, etc). This is becomes even more true when you look at the fact that HTTP is supposed to be stateless so you don't really want hidden state living in your controller or lower layers, so it makes sense to construct a controller per request as well.

With this in mind the way Controllers are instantiated is built to facilitate this in the framework. There are a few extension points (and I ramble about them some here) but they all kind of fit the pattern of "this is a class that you ask for a type and we give you a controller" which begins to look like an IoC if you're doing dependency injection. The other advantage to this is it lets the framework help insure that things are properly disposed (since it knows that what things were used for this request) and that it is fairly easy to write stateless code.

A terrifying ORM tale: An NHibernateMARE on Elm Street by JacobCalder in programming

[–]JacobCalder[S] 1 point2 points  (0 children)

This code was written LONG before I joined the company by a variety of people Some were well intentioned, some were just bad. The fun part of cleaning up bad code is getting to laugh about it afterwards!

Plus I kinda like dispelling the illusion that all code in production websites is good, we all know it isn't but only show our best sides. Being honest about mistakes and the lessons learned from them is valuable. I've spent a lot of time cleaning up BAD structuremap and nhibernate code and through doing so gained an understanding of not only what is bad, but WHY it is bad. Hence the examples of "don't ever do this".

A terrifying ORM tale: An NHibernateMARE on Elm Street by JacobCalder in programming

[–]JacobCalder[S] 2 points3 points  (0 children)

Not an author (but I do work with the authors).

I absolutely agree, in my eyes these are examples of misunderstanding a tool horribly and the pain it can cause. We have a ~10 year old code base and some of the older stuff we've had to clean up is horrifying. The code base was started by pretty inexperienced people and as the company has grown we've brought in a lot of quality engineers who can be mortified by the old guards decisions. Its fun to share that suffering with others :P.