45
F101 - Behaviors, Configuration, and Runtime

F101 - Behaviors, Configuration, and Runtime

Embed Size (px)

Citation preview

Page 1: F101 - Behaviors, Configuration, and Runtime

F101 - Behaviors, Configuration, and Runtime

Page 2: F101 - Behaviors, Configuration, and Runtime

About the Author

Joshua ArnoldChief Software Architect, Perioperative Logistics

http://www.linkedin.com/in/joshuaarnold

http://twitter.com/jmarnold

http://josharnold.lostechies.com

Josh leads the development efforts for the Logistics team and is a principal developer on the Fubu-family of frameworks.

He is a husband, expectant father, passionate software craftsman, coach, closet musician, and perpetual learner.

Page 3: F101 - Behaviors, Configuration, and Runtime

Goals

Understand the underlying model that makes FubuMVC

Page 4: F101 - Behaviors, Configuration, and Runtime

What’s in an Action?

users/jmarnold

Page 5: F101 - Behaviors, Configuration, and Runtime

What’s in an Action?

users/jmarnoldo {controller}/{action}

Page 6: F101 - Behaviors, Configuration, and Runtime

What’s in an Action?

users/jmarnoldo {controller}/{action}

• UsersController.Show(string username)

Page 7: F101 - Behaviors, Configuration, and Runtime

What’s in an Action?

Routing

Web Framework

Method Invocation

users/jmarnold

{controller}/{action}

UsersController.Show(string username)

Page 8: F101 - Behaviors, Configuration, and Runtime

What’s in an Action?

Web Framework

Given some {route}: 1. Locate the Method for that route 2. Invoke that Method

Page 9: F101 - Behaviors, Configuration, and Runtime

What’s in an Action?

Method Invocation

Type

MethodInfo

Page 10: F101 - Behaviors, Configuration, and Runtime

What’s in an Action?

ActionCall

Type

MethodInfo

Page 11: F101 - Behaviors, Configuration, and Runtime

Action Calls

Analogous to “Controller Actions” Can come from anywhere – it’s just a glorified delegate

descriptor

Key Term: ActionCall

Page 12: F101 - Behaviors, Configuration, and Runtime

Request/Response

Given some {route}: 1. Locate the Method for that route 2. Invoke that Method 3. Render the respective view

Page 13: F101 - Behaviors, Configuration, and Runtime

Request/Response

Given some {route}:

1. Locate the Method for that route

Routing

Web Framework

Method Invocation

View Rendering

2. Invoke that Method

3. Render the respective view

Page 14: F101 - Behaviors, Configuration, and Runtime

The Pipeline

Method Invocation View Rendering

Page 15: F101 - Behaviors, Configuration, and Runtime

The Pipeline

ActionCall Output

Page 16: F101 - Behaviors, Configuration, and Runtime

The Pipeline

ActionCall Output

BehaviorNode

Key Term: BehaviorNode

Page 17: F101 - Behaviors, Configuration, and Runtime

The Pipeline

ActionCall Output

“Invoke this method” “Render the output”

Page 18: F101 - Behaviors, Configuration, and Runtime

The Pipeline

ActionCall Output

“Invoke this method” “Render the output”

IFubuRequest

“…and put the return value in here” “Get the data from here and…”

Page 19: F101 - Behaviors, Configuration, and Runtime

BehaviorChain

Configuration Model

Node 1 Node 2 Node 3

Page 20: F101 - Behaviors, Configuration, and Runtime

Behavior Chains

Essentially a linked list of Behavior Nodes Describes the order in which behavior nodes will execute

for a given request Can be identified by:

o Guido Input Model Type

Key Term: BehaviorChain

Page 21: F101 - Behaviors, Configuration, and Runtime

Request/Response

Given some {route}:

1. Locate the Method for that route

Routing

Web Framework

Method Invocation

View Rendering

2. Invoke that Method

3. Render the respective view

Page 22: F101 - Behaviors, Configuration, and Runtime

Request/Response

Given some {route}:

1. Find the BehaviorChain for that route

Routing

FubuMVC

Resolve Chain

Execute Chain

2. Invoke that BehaviorChain

*

*Not exactly how we do it, but we’ll clarify later

Page 23: F101 - Behaviors, Configuration, and Runtime

users/jmarnold

Chain Execution - Configuration

UsersController.Show(“jmarnold”) WebFormOutputNode

Page 24: F101 - Behaviors, Configuration, and Runtime

Chain Execution - Runtime

UsersController.Show(“jmarnold”)

Render WebForms View

Page 25: F101 - Behaviors, Configuration, and Runtime

Runtime: Russian Dolls

Full control over execution of next behavioro Transactionso Using statementso Etc.

You can decide not to execute the nexto You can even decide to do something else instead

Page 26: F101 - Behaviors, Configuration, and Runtime

Models/Terminology

Configuration:o BehaviorChaino BehaviorNode

Runtime:o IActionBehavior

Page 27: F101 - Behaviors, Configuration, and Runtime

One More Time

Configuration:

Node 1 Node 2 Node 3

Page 28: F101 - Behaviors, Configuration, and Runtime

One More Time

Runtime: Node 1

Node 2

Node 3

Page 29: F101 - Behaviors, Configuration, and Runtime

Intermission

Grab some coffee Ask some questions Make sure we’re all on the same page here

Page 30: F101 - Behaviors, Configuration, and Runtime

Behavior Chain Construction

ActionCalls are registered through either of the following:

o Conventional discovery (as stated in your FubuRegistry)o IActionSource implementations registered in your FubuRegistry

Page 31: F101 - Behaviors, Configuration, and Runtime

Behavior Chain Construction

FubuRegistry BehaviorGraph

BehaviorChain 1

BehaviorChain 2

Assembly Scanning

IActionSources

Key Term: BehaviorGraph

Page 32: F101 - Behaviors, Configuration, and Runtime

Routing Integration

BehaviorChain

ActionCall Output

Page 33: F101 - Behaviors, Configuration, and Runtime

Routing Integration

BehaviorChain

ActionCall Output

IUrlPolicy

Route

Page 34: F101 - Behaviors, Configuration, and Runtime

Request/Response

Given some {route}:

1. Find the BehaviorChain for that route

Routing

FubuMVC

Resolve Chain

Execute Chain

2. Invoke that BehaviorChain

*

*Not exactly how we do it, but we’ll clarify later

Page 35: F101 - Behaviors, Configuration, and Runtime

Request/Response

Given some {route}:

1. Find the BehaviorChain for the route, via the BehaviorGraph, using the configured Guid

Routing

FubuMVC

Resolve Chain

Execute Chain2. Invoke that BehaviorChain

Page 36: F101 - Behaviors, Configuration, and Runtime

Who Cares?

Behaviors seem cool…o What’s the point?

Page 37: F101 - Behaviors, Configuration, and Runtime

How about an example?

Page 38: F101 - Behaviors, Configuration, and Runtime

…And Again…

Page 39: F101 - Behaviors, Configuration, and Runtime

What if we could…

Page 40: F101 - Behaviors, Configuration, and Runtime

What if we could…

ActionCall(CreateEntityAction<TEntity>)

Page 41: F101 - Behaviors, Configuration, and Runtime

What if we could…

ActionCall(CreateEntityAction<TEntity>)

IUrlPolicy

{entity}/create

Page 42: F101 - Behaviors, Configuration, and Runtime

Reusable Actions

Why repeat yourself when you don’t have to?

Page 43: F101 - Behaviors, Configuration, and Runtime

Reusable Behaviors

Why invoke an ActionCall if the input isn’t valid? o Use a “Validation Behavior”

Page 44: F101 - Behaviors, Configuration, and Runtime

Question Time

Page 45: F101 - Behaviors, Configuration, and Runtime

Where to go from here…

…you tell me:

View Engines & Html Conventions? Custom Behaviors? FubuRegistry DSL?