structure mapping your way to better software

18
StructureMapping Your Way to Better Software Matt Honeycutt @matthoneycutt http://trycatchfail.com

Upload: matthoneycutt

Post on 22-May-2015

332 views

Category:

Technology


1 download

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

StructureMapping Your Way to Better Software

Matt Honeycutt@matthoneycutt

http://trycatchfail.com

Page 2: Structure mapping your way to better software

The Plan

Better software?

StructureMap Basics

StructureMap in Action

Advanced Recipes

Page 3: Structure mapping your way to better software

SOLID Principles

Single Responsibility

Open-Closed

Liskov Substitution

Interface Segregation

Dependency Inversion

Page 4: Structure mapping your way to better software

SOLID

Page 5: Structure mapping your way to better software

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

Code!

Page 7: Structure mapping your way to better software

Everyone Loves WebForms!

Page 8: Structure mapping your way to better software
Page 9: Structure mapping your way to better software

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

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

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

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

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

Decorator Pattern

InMemoryProductRepository : IProductRepository

ProductLoggingDecorator: IProductRepository

SomeOtherDecorator: IProductRepository

Page 15: Structure mapping your way to better software

Think compositionally!“Favor composition over inheritance!”

Page 16: Structure mapping your way to better software

We’ve only just begun!

Page 17: Structure mapping your way to better software

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

Want to know more?

http://trycatchFAIL.comBlog, Videos, and

More!

@matthoneycuttI might say something interesting some day…