structure mapping your way to better software
DESCRIPTION
Slides corresponding to my devLink 2012 talk on StructureMap. Get the code at https://github.com/MattHoneycutt/Presentations, and find more info at http://trycatchfail.com.TRANSCRIPT
![Page 1: Structure mapping your way to better software](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e76c1d8b42a34098b571e/html5/thumbnails/1.jpg)
StructureMapping Your Way to Better Software
Matt Honeycutt@matthoneycutt
http://trycatchfail.com
![Page 2: Structure mapping your way to better software](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e76c1d8b42a34098b571e/html5/thumbnails/2.jpg)
The Plan
Better software?
StructureMap Basics
StructureMap in Action
Advanced Recipes
![Page 3: Structure mapping your way to better software](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e76c1d8b42a34098b571e/html5/thumbnails/3.jpg)
SOLID Principles
Single Responsibility
Open-Closed
Liskov Substitution
Interface Segregation
Dependency Inversion
![Page 4: Structure mapping your way to better software](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e76c1d8b42a34098b571e/html5/thumbnails/4.jpg)
SOLID
![Page 5: Structure mapping your way to better software](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e76c1d8b42a34098b571e/html5/thumbnails/5.jpg)
Why Use StructureMap?
• Achieve loose coupling• Extensibility everywhere• Improve testability• SOLID!
Design
• Mature: one of the oldest containers• One of the fastest IoC containers• Easy to learn Domain Specific Language• Fully-loaded
Features
![Page 6: Structure mapping your way to better software](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e76c1d8b42a34098b571e/html5/thumbnails/6.jpg)
Code!
![Page 7: Structure mapping your way to better software](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e76c1d8b42a34098b571e/html5/thumbnails/7.jpg)
Everyone Loves WebForms!
![Page 8: Structure mapping your way to better software](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e76c1d8b42a34098b571e/html5/thumbnails/8.jpg)
![Page 9: Structure mapping your way to better software](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e76c1d8b42a34098b571e/html5/thumbnails/9.jpg)
Service Locator
Design pattern which encapsulates the processes involved in obtaining a service.
Requester
Asks the locator for a particular service.
Service Locator
Based on configuration, builds up and returns the requested
service.
![Page 10: Structure mapping your way to better software](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e76c1d8b42a34098b571e/html5/thumbnails/10.jpg)
Model-View-Presenter
MVP is a user interface design pattern engineered to improve the separation of concerns within an
application’s presentation layer.
Model
Object that defines the data to be displayed.
View
Interface that displays the data.
Presenter
Acts upon the model, tells the
view what to do.
![Page 11: Structure mapping your way to better software](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e76c1d8b42a34098b571e/html5/thumbnails/11.jpg)
ASP.NET MVC DependencyResolver
DependencyResolverASP.NET MVC
Pipeline
Hey, give me the HomeController!
Here ya go!
Activator.CreateInstance(typeof(HomeController));
http://mysite/Home/Index
![Page 12: Structure mapping your way to better software](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e76c1d8b42a34098b571e/html5/thumbnails/12.jpg)
ASP.NET MVC DependencyResolver
SmDependencyResolverASP.NET MVC
Pipeline
Hey, give me the HomeController!
Here ya go!
Container.GetInstance(typeof(HomeController));
![Page 13: Structure mapping your way to better software](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e76c1d8b42a34098b571e/html5/thumbnails/13.jpg)
Decorator Pattern
Design pattern that allows behavior to be added to an object at runtime.
Service Interface
Defines the public contract for the type
being extended.
Decorated Type
Base type that implements in the interface.
Decorator
Wraps an instance of the service
interface to add new behavior.
![Page 14: Structure mapping your way to better software](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e76c1d8b42a34098b571e/html5/thumbnails/14.jpg)
Decorator Pattern
InMemoryProductRepository : IProductRepository
ProductLoggingDecorator: IProductRepository
SomeOtherDecorator: IProductRepository
![Page 15: Structure mapping your way to better software](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e76c1d8b42a34098b571e/html5/thumbnails/15.jpg)
Think compositionally!“Favor composition over inheritance!”
![Page 16: Structure mapping your way to better software](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e76c1d8b42a34098b571e/html5/thumbnails/16.jpg)
We’ve only just begun!
![Page 17: Structure mapping your way to better software](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e76c1d8b42a34098b571e/html5/thumbnails/17.jpg)
To Recap
IoC rocks. Use it. Embrace it!
There’s a learning curve… but it’s worth it!
Makes it easier to create SOLID code.
Do it all with StructureMap!
![Page 18: Structure mapping your way to better software](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e76c1d8b42a34098b571e/html5/thumbnails/18.jpg)
Want to know more?
http://trycatchFAIL.comBlog, Videos, and
More!
@matthoneycuttI might say something interesting some day…