-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
188 lines (151 loc) · 11.4 KB
/
index.html
File metadata and controls
188 lines (151 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="generator" content="Bootply" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>StructureMap - A Gentle Quickstart</title>
<link href="/content/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="/content/prism.css" rel="stylesheet" type="text/css" />
<link href="/content/theme.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" />
<link rel="icon" type="image/x-icon" href="/content/images/structuremap-logo.ico">
<link rel="icon" type="image/png" href="/content/images/structuremap-logo-60x60.png">
<link rel="apple-touch-icon" type="image/png" href="/content/images/structuremap-logo-60x60.png">
<link rel="apple-touch-icon" type="image/png" sizes="72x72" href="/content/images/structuremap-logo-72x72.png">
<link rel="apple-touch-icon" type="image/png" sizes="114x114" href="/content/images/structuremap-logo-114x114.png">
<link rel="apple-touch-icon" type="image/png" sizes="144x144" href="/content/images/structuremap-logo-144x144.png">
<!-- CSS code from Bootply.com editor -->
<link href="/content/affix.css" rel="stylesheet" type="text/css" />
</head>
<!-- HTML code from Bootply.com editor -->
<body >
<a href="https://github.com/structuremap/structuremap"><img style="z-index: 5000; position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/e7bbb0521b397edbd5fe43e7f760759336b5e05f/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677265656e5f3030373230302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png"></a>
<nav class="navbar navbar-default navbar-fixed-top" role="banner">
<div class="container">
<div class="navbar-header">
<a href="/" class="navbar-brand">StructureMap 4.7.0</a>
</div>
<nav class="collapse navbar-collapse" role="navigation">
<ul class="nav navbar-nav pull-right">
<li>
<a href="/quickstart">A Gentle Quickstart</a>
</li>
<li>
<a href="/documentation">Documentation</a>
</li>
<li>
<a href="https://groups.google.com/forum/#!forum/structuremap-users">Google Group</a>
</li>
<li>
<a href="https://gitter.im/structuremap/structuremap?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"><img src="https://camo.githubusercontent.com/da2edb525cde1455a622c58c0effc3a90b9a181c/68747470733a2f2f6261646765732e6769747465722e696d2f4a6f696e253230436861742e737667" alt="Join the chat at https://gitter.im/structuremap/structuremap" data-canonical-src="https://badges.gitter.im/Join%20Chat.svg" style="max-width:100%;"></a>
</li>
<li><a href="/roadmap" title="Roadmap">Previous</a></li>
<li><a href="/glossary" title="Glossary">Next</a></li>
</ul>
<div class="navbar-form navbar-left" role="search">
<div class="form-group">
<input id="search" type="search" class="form-control" placeholder="Search">
</div>
</div>
</nav>
</div>
</nav>
<div class="container">
<nav class="navbar-inverse">
<ol class="breadcrumb"><li><a href="/">StructureMap</a></li><li class="active">A Gentle Quickstart</li></ol>
</nav>
</div>
<!--main-->
<div class="container">
<div class="row">
<!--left-->
<div class="col-md-3" id="leftCol">
<ul class="nav nav-stacked affix" id="sidebar">
<li><h3><img src="/content/images/structuremap-logo-210x210.png" alt="StructureMap 4.7.0" width="210" height="210"></h3></li>
<li><h3 class="no-margin">Next</h3><p><a href="/glossary">Glossary</a></p></li>
<li><h3 class="no-margin">Previous</h3><a href="/roadmap">Roadmap</a></p></li>
</ul>
</div><!--/left-->
<!--right-->
<div class="col-md-9">
<h1>A Gentle Quickstart <a href="https://github.com/structuremap/structuremap/blob/master/documentation/quickstart.md" class="text-muted small pull-right fa fa-github" style="margin-top: 10px"> Edit on GitHub</a></h1>
<hr />
<div id="main-pane">
<!--Title: A Gentle Quickstart-->
<!--Url: quickstart-->
<p>The first thing you should know is that StructureMap (and other IoC tools like it) are designed to
make compositional and modular software designs easier to build by offloading the grubby mechanics of
resolving dependencies, reading configuration data, and assembling object graphs to the IoC tool instead
of cluttering up your application code.</p>
<p>Before you get started with StructureMap it's recommended that you first get comfortable with the <a href="/software-design-concepts">Software Design Concepts</a>
of <a href="http://codebetter.com/jeremymiller/2005/10/06/the-dependency-injection-pattern-%E2%80%93-what-is-it-and-why-do-i-care/">Dependency Injection</a>
and <a href="http://codebetter.com/jeremymiller/2005/09/20/what%E2%80%99s-so-great-about-inversion-of-control/">Inversion Of Control</a>.
It's important that you structure and build your application with these concepts in mind to fully utilize StructureMap's abilities.</p>
<p>Assuming that you're already familiar with those concepts, or you'd really rather skip the pedantry and jump right into concrete code, the first thing to do is, go <a href="/get-structuremap">Get StructureMap</a> and jump into usage.</p>
<h2 id="main-usage">Main Usage</h2>
<p>By and large, you really only do two kinds of things with StructureMap:</p>
<ol>
<li><p>Configure the container by registering the <strong>what</strong> and <strong>how</strong> StructureMap should build or find requested services based on a type and/or name.</p>
</li>
<li><p>Resolve object instances of a service or dependency built out with all of its dependencies.</p>
</li>
</ol>
<p>So let's say that you have a simple object model like so:</p>
<pre><code class="language-csharp">
public interface IBar
{
}

public class Bar : IBar
{
}

public interface IFoo
{
}

public class Foo : IFoo
{
 public IBar Bar { get; private set; }

 public Foo(IBar bar)
 {
 Bar = bar;
 }
}

</code></pre>
<p>You could explicitly build a StructureMap <code>Container</code> object to build these types like this:</p>
<pre><code class="language-csharp">
// Configure and build a brand new
// StructureMap Container object
 var container = new Container(_ =>
 {
 _.For<IFoo>().Use<Foo>();
 _.For<IBar>().Use<Bar>();
 });

// Now, resolve a new object instance of IFoo
 container.GetInstance<IFoo>()
 // should be type Foo
 .ShouldBeOfType<Foo>()

 // and the IBar dependency too
 .Bar.ShouldBeOfType<Bar>();


</code></pre>
<p>or utilize StructureMap's type scanning conventions to configure the relationships and do the same thing like this:</p>
<pre><code class="language-csharp">
var container = new Container(_ =>
{
 _.Scan(x =>
 {
 x.TheCallingAssembly();
 x.WithDefaultConventions();
 });
});

container.GetInstance<IFoo>()
 .ShouldBeOfType<Foo>()
 .Bar.ShouldBeOfType<Bar>();

</code></pre>
<h2 id="integrating-structuremap-within-your-application">Integrating StructureMap within your application</h2>
<p>At some point you will want to integrate StructureMap into your application. Whether you are using Windows Presentation Foundation (WPF), FubuMVC, ASP.NET WebForms, ASP.NET MVC or any other framework or technology, you will have to do some sort of plumbing and bootstrapping. Depending on the used technology or framework there can be important integration points that you will have to use to fully enable the power of StructureMap.</p>
<p>While StructureMap doesn't provide integration support out of the box for all of the frameworks and technologies out there, we do find it important to help you get started with integrating StructureMap into your application. That said, StructureMap does provide integration support for <a href="https://fubumvc.github.io/">FubuMVC</a> (a web framework, which is part of the same family as StructureMap).</p>
<h2 id="what-to-do-when-things-go-wrong">What to do when things go wrong?</h2>
<p>StructureMap, and any other IoC tool for that matter, is configuration intensive, which means that their will be problems in that configuration. We're all moving to more convention based type registration, so more stuff is happening off stage and out of your sight, making debugging the configuration even trickier. Not to worry (too much), StructureMap has some diagnostic abilities to help you solve configuration problems:</p>
<ul>
<li><a href="/interpreting-exceptions">Interpreting Exceptions</a></li>
<li><a href="/diagnostics">Diagnostics</a></li>
</ul>
<h2 id="need-help">Need Help?</h2>
<ul>
<li>There is a <a href="http://groups.google.com/group/structuremap-users?hl=en">google group</a> for StructureMap support.</li>
<li>You can ask questions on <a href="http://stackoverflow.com/">StackOverflow</a> with the tag "structuremap."</li>
</ul>
</div>
<hr />
<nav>
<span>
<strong>Previous: </strong><a href="/roadmap">Roadmap</a>
</span>
<span class="pull-right">
<strong>Next: </strong><a href="/glossary">Glossary</a>
</span>
</nav>
</div><!--/right-->
</div><!--/row-->
</div><!--/container-->
</body>
<foot>
<script type='text/javascript' src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type='text/javascript' src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/content/embed.js"></script>
<script type="text/javascript" src="/content/prism.js"></script>
<script type="text/javascript" src="/content/sidebar.js"></script>
<script type="text/javascript" src="/content/affix.js"></script>
<script>
$('#search').keyup(function(e){
if(e.keyCode == 13) {
var search = $('#search').val();
var url = 'https://www.google.com/#q=site:structuremap.github.io ' + search;
url = encodeURI(url);
//alert(url);
window.location.href = url;
e.stopPropagation();
if (e.cancelBubble!=null) e.cancelBubble = true;
return false;
}
});
</script>
</foot>
</html>