introduction to xaml with wpfexamples dependency injection •unity, mef, ninject, autofac,...

48
ABSTRACT ART GETTING ABSTRACTION “JUST RIGHT” Presented by Jeremy Clark www.jeremybytes.com

Upload: others

Post on 27-Jul-2020

15 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

ABSTRACT ARTGETTING ABSTRACTION “JUST RIGHT”

Presented by Jeremy Clarkwww.jeremybytes.com

Page 2: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

Geek & Poke – http://goo.gl/ifd53l

A Good Design

is like

A Piece of Art

@jeremybytes

Page 3: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

ABSTRACTION IS AWESOME!

Maintain TestExtend

@jeremybytes

Page 4: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

ABSTRACTION IS AWFUL!

ComplexityDebugging

DifficultyConfusion

Frustration@jeremybytes

Page 5: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

https://archive.org/details/goldilocks_and_the_three_bears

Page 6: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

GOLDILOCKS THE DEVELOPER

Too MuchAbstraction

Too LittleAbstraction

Just Right

@jeremybytes

Page 7: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

TWO TYPES OF DEVELOPERS

Over-Abstractor

Under-Abstractor

@jeremybytes

Page 8: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

• “We’ll have a good use for this in the future.”

• Overly Complex

• Difficult to Maintain

Over-Abstractor

@jeremybytes

Page 9: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

A Good Architect Leaves A Footprint

Geek & Poke: http://goo.gl/B4uXa3

@jeremybytes

Page 10: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

• “Let’s keep things simple.”

• Rigid

• Difficult to Maintain

Under-Abstractor

@jeremybytes

Page 11: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

COMMON PROBLEM

• “We’ll have a good use for this in the future.”

• Overly Complex

• Difficult to Maintain

Over-Abstractor

• “Let’s keep things simple.”

• Rigid

• Difficult to Maintain

Under-Abstractor

@jeremybytes

Page 12: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

The Default State Quiz

Who Are You?

Page 13: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

Let’s build a plug-in architecture…

Awesome!

Let’s do it.

Maybe we

should look at

compile-time

options.

Page 14: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

We need to share a value between

modules…

I’ll create an

object state

manager.

Let’s use a

global variable.

Page 15: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

How should we do the UI?

Here’s a new

JavaScript

framework.

Let’s use the

same framework

we did last time.

Page 16: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

Pull data from a database…

ORMs are

awesome!

SELECT *

FROM Customers

WHERE ID = [@id]

Page 17: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

We need an object instance…

var logger =

DIContainer

.Resolve<ILogger>()

var logger =

new FileLogger()

Page 18: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

Neither answer is right or wrong. The correct response is “It depends.”

—Jeremy’s Standard Response

Page 19: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

Let’s build a plug-in architecture…

Awesome!

Let’s do it.

Maybe we

should look at

compile-time

options.

Page 20: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

We need to share a value between

modules…

I’ll create an

object state

manager.

Let’s use a

global variable.

Page 21: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

How should we do the UI?

Here’s a new

JavaScript

framework.

Let’s use the

same framework

we did last time.

Page 22: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

Pull data from a database…

ORMs are

awesome!

SELECT *

FROM Customers

WHERE ID = [@id]

Page 23: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

We need an object instance…

var logger =

DIContainer

.Resolve<ILogger>()

var logger =

new FileLogger()

Page 24: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

BE HONEST WITH YOURSELF

Too MuchAbstraction

Too LittleAbstraction

Just Right

@jeremybytes

Page 25: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

WHO AM I?

•Hello. My name is Jeremy, and I’m an Under-Abstractor.

Under-Abstractor

“Keep Things Obvious”“Don’t Be Tricky”

Page 26: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

REPORTING APPLICATION

Page 27: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

THE PENDULUM EFFECT

Over-Abstraction

Under-Abstraction

Just Right

Page 28: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

THOSE AROUND YOU

•Jeff loved to build components.

•He liked to create code for re-use.

•He thought of all possible scenarios.

Over-Abstractor

Page 29: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

A SYMBIOTIC RELATIONSHIP

The Over-Abstractor

helps the Under-Abstractor

get things Just Right

The Under-Abstractor

helps theOver-Abstractor

get things Just Right

Page 30: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

Know Your…

Environment

Self

Tools

Infrastructure

Business

Team

Page 31: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

THE PENDULUM EFFECT

Over-Abstraction

Under-Abstraction

Just Right

@jeremybytes

Page 32: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

VARIOUS DATA SOURCES

MongoDB

Amazon AWS

Microsoft Azure

WebAPI

CSV SOAP Service

Microsoft SQL Server

Oracle

JSON Hadoop

@jeremybytes

Page 33: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

PLUGGABLE REPOSITORIES

@jeremybytes

Service

Repository

CSV File

Repository

SQL Database

Repository

Application

Page 34: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

@jeremybytes

Page 35: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

DRY

• Don’t Repeat Yourself

@jeremybytes

Under-Abstractor

Page 36: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

DON’T REPEAT YOURSELF

Consolidate Similar Code

Avoid Copy/Paste

Copy/PastaSpaghetti

Code

@jeremybytes

Page 37: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

SoC

• Separation of Concerns

@jeremybytes

Under-Abstractor

Page 38: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

SINGLE RESPONSIBILITY PRINCIPLE

Complements Separation of

Concerns

The “S” in S.O.L.I.D.

A class should have only one

reason to change

A class shoulddo one thing

(and do it well)

@jeremybytes

Page 39: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

YAGNI

• You Ain’t Gonna Need It

• (You Aren’t Going to Need It)

@jeremybytes

Over-Abstractor

Page 40: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

MORAL OF YAGNI

• Code for the features you have now

• Add abstraction as you need it

• Don’t add abstraction based on speculation

We still think about the future, but we don’t implement it yet.

@jeremybytes

Page 41: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

KISS

• Keep It Simple, Stupid

• (Keep It Short & Simple)

• (Keep It Simple & Straightfoward)

@jeremybytes

Over-Abstractor

Page 42: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

DDIY

• Don’t Do It Yourself

@jeremybytes

Over-Abstractor

Under-Abstractor

Page 43: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

DDIY

•Over-Abstractors like to build things to solve specific problems

Over-Abstractor

•Under-Abstractors shy away from external frameworks and libraries

Under-Abstractor

@jeremybytes

Page 44: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

EXAMPLES

Dependency Injection

• Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET

Unit Testing Framework

• MSTest, NUnit, TypeMock Isolator, xUnit.net, Approval Tests

Mocking

• Moq, NSubstitute, RhinoMocks, FakeItEasy, JustMock

Logging

• log4net, Semantic Logging Application Block (SLAB)

UI Framework

• Prism, Angular, React

@jeremybytes

Page 45: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

ABSTRACTION IS AWESOME& AWFUL

Maintain TestExtend

ComplexityDebugging

DifficultyConfusion

@jeremybytes

Page 46: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

THE GOLDILOCKS PRINCIPLE

Too MuchAbstraction

Too LittleAbstraction

Just Right

@jeremybytes

Page 47: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

GETTING THINGS RIGHT

DRY

• Don’t Repeat Yourself

SoC

• Separation of Concerns

YAGNI

• You Ain’tGonna Need It

KISS

• Keep It Short & Simple

DDIY

• Don’t Do It Yourself

@jeremybytes

Page 48: Introduction to XAML with WPFEXAMPLES Dependency Injection •Unity, MEF, Ninject, Autofac, StructureMap, Spring.NET Unit Testing Framework •MSTest, NUnit, TypeMock Isolator, xUnit.net

THANK YOU!

Jeremy Clark

•http://www.jeremybytes.com

[email protected]

•@jeremybytes

@jeremybytes