<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www.lostechies.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Marcus The Blog (by MarcusTheBold)</title><subtitle type="html" /><id>http://www.lostechies.com/blogs/marcus_bratton/atom.aspx</id><link rel="alternate" type="text/html" href="http://www.lostechies.com/blogs/marcus_bratton/default.aspx" /><link rel="self" type="application/atom+xml" href="http://www.lostechies.com/blogs/marcus_bratton/atom.aspx" /><generator uri="http://communityserver.org" version="4.1.30929.2835">Community Server</generator><updated>2007-08-02T22:06:00Z</updated><entry><title>A philosophical discussion about Inversion of Control frameworks</title><link rel="alternate" type="text/html" href="/blogs/marcus_bratton/archive/2010/01/10/a-philosophical-discussion-about-inversion-of-control-frameworks.aspx" /><id>/blogs/marcus_bratton/archive/2010/01/10/a-philosophical-discussion-about-inversion-of-control-frameworks.aspx</id><published>2010-01-10T21:19:00Z</published><updated>2010-01-10T21:19:00Z</updated><content type="html">&lt;p&gt;I had a short conversation with Chad Myers today over twitter (a
very challenging medium to have a conversation of any substance over,
and frustrating). Basically, it was about my effort with Siege.ServiceLocation. I thought I would clear up some misconceptions.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Siege.ServiceLocation isn't an abstraction, it's a decoupling.&lt;br /&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Siege.ServiceLocation isn't just about contextual
registration/resolution (though that was the initial impetus). It's not
about resolution at all. It's about expressing registration. It's about
adding functionality to ALL containers. There are a few things that I
am trying to accomplish with this library. First, I want to decouple
registration from resolution. That's not to say I want to abstract how
each container's registration is performed; &lt;b&gt;I want them decoupled completely. &lt;/b&gt;Second, I want my library to be functionally compatible with existing frameworks (see &lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/06/introducing-siege.aspx"&gt;Siege Design Philosophy&lt;/a&gt;
for more details). This means whatever Siege.ServiceLocation can do,
all the frameworks it integrates with can do. Third, I want it to be
easy. Outside of Ninject (which I think is a wonderfully built IoC), I
think the others fail the third criteria. I've worked with them all. I
know the differences. They each have distinct problems. And I don't
think it has to be that way.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Inversion of Control containers should be about resolving types&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Not about registering types. Registration is a way of instructing an
IoC how to resolve a type. It's not what the IoC is built for, it's a
way of expressing what the IoC needs to do. Each IoC has a different
way of accomplishing the same thing. I've been told that choosing an
IoC is about evaluating the strengths and weaknesses of each framework
and picking the one that suits your needs.&lt;/p&gt;
&lt;p&gt;What? If an IoC is there to resolve types and their dependencies, to
provide a mechanism to help you decouple your code, then how can there
be strengths and weaknesses in each framework? Is it in terms of how
efficiently they perform the task? Is it in terms of they internally
manage resolution?&lt;/p&gt;
&lt;p&gt;Or is it in terms of what their registration syntax allows you to
do? Is it in terms of how you express your goal? Is it in terms of the
instructions the container understands when it tries to resolve a type?&lt;/p&gt;
&lt;p&gt;These are all rhetorical questions. The point is to look at the
problem differently than has been traditionally done. To my mind, there
is a clear seperation of concerns between the responsibility of
registering types and the responsibility of resolving types. I think an
IoC should specialize in resolving types and their dependencies, not
specialize in expressing how to resolve types and their dependencies.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Siege.ServiceLocation is not an IoC&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;It's a coordination mechanism for an IoC container. Think "one level
above" the container. Rather than instructing an IoC container how to
resolve your type, you instruct Siege.ServiceLocation. It then in turn
knows how to interact with the underlying framework to get what you
want. It tracks the conditions and criteria. It makes all the requests
necessary through the underlying framework to get your objects
constructed. Think of it as a proxy with an adapter. The goal is to
track runtime conditions to facilitate the selection of an appropriate
interface. To enable this functionality WITHOUT having to force you to
use a specific framework. Where the IoC container specializes in
resolution, Siege.ServiceLocation specializes in registration and
communicating requests to the IoC container.&lt;/p&gt;
&lt;p&gt;The reason that each IoC framework has strengths and weaknesses is
because each IoC has it's own way of trying to go about describing how
they want things resolved. That means that some of them can interpret
certain resolution instructions. Others interpret their own resolution
instructions. That's not the point of an IoC, and it's no wonder they
all do it differently and each has their own strengths and weaknesses. &lt;/p&gt;
&lt;p&gt;If we move the registration expression above the container that
performs resolution, we can decouple these two concepts. Then, as long
as the component that understands registration can express instructions
to the component that performs resolution, all containers can suddenly
benefit from these collective strengths. We remove the need for
containers to worry about these concerns. We remove the need for
developers to do an analysis of what "features" a container supports.
We remove the need for people to make trade-offs on what strengths they
gain, what weaknesses they are burdened with and what features they
lose out on when choosing an IoC framework.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;The Least Common Denominator&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;In my brief conversation with Chad, he pointed out that most
abstraction attempts only manage to accomplish the Least Common
Denominator of all frameworks and wind up gutting the potential of each
of the frameworks they integrate with. I understand his point, but I
think this is fundamentally different. The desire is NOT to limit you
to what all frameworks have in common, but to allow people to use
functionality that may NOT exist in all frameworks. A primary example
of this is contextual resolution. Several IoCs can do this to some
extent or another, based on very narrow criteria. Some of them can't do
it at all. None of them can respond to evolving runtime conditions when
selecting an implementation of a requested type.&lt;/p&gt;
&lt;p&gt;When combining these containers with Siege, suddenly all of them
gain this ability. This is because Siege understands both how to
accomplish what you are requesting (it's specialty is in extensible
registration) and how to communicate with a container to achieve it's
goal (for example, when condition a is met, request type a. when
condition b is met, request type b). On top of that, it instructs the
container on how to call back to Siege for &lt;b&gt;each dependency&lt;/b&gt; that a container has to resolve for additional instructions on how to perform resolution.&lt;/p&gt;
&lt;p&gt;This means that by using Siege you can gain functionality that your
selected container doesn't natively support. And as Siege's use cases
grow, ALL containers functionality will grow. A rising tide lifts all
boats. If the strengths of each container were built as registration
expressions into Siege, &lt;b&gt;all containers&lt;/b&gt; would gain this
strength. You would would sacrifice nothing, make no trade-offs and not
be required to learn multiple distinct ways to express how you want a
type resolved.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Limiting your choices&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;One of the design philosophies behind this project is NOT to limit
your choices. It's to expand them. If Siege doesn't support something
that a specific container does, use that container with Siege. Do their
specialized registration to configure the container and then give it to
Siege to do whatever additional registration expressions you need to.
With this approach, we avoid any LCD philosophy, we avoid limiting the
your choices as a developer. Alternatively, you can easily extend the
framework to accomplish what you want so you don't have to change
containers or feel constrained to a specific one. On top of that, we
deliver functionality that you would not have otherwise. And hopefully,
as the framework grows and evolves, you won't have to learn 5 different
ways of registering and resolving types. You'll only have to learn one,
and no matter which underlying framework you use, all of them will
support your system fully. But, that's down the road from where we are
today, which is why I made it an important design decision to be sure
we didn't rob any underlying IoC of it's functionality.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Evolution&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;I'll be the first to admit, this wasn't the direction that I was
going when I first started working on this. I wanted to do an 80/20.
But my point of view has evolved over the last month and my efforts
have gone towards supporting the idea that functionality can and will
be introduced to all containers through Siege. Some of the things I've
had to say in this post contradict what I've said in previous posts
(perhaps I should update them?) But that comes with an evolving point
of view. It's organic. Things will grow and change. And I want to thank
Chad for challenging me and making me think more in depth about how to
articulate where I'm going and what I'm doing so I could put up a post
like this.&lt;/p&gt;
&lt;p&gt;Let each framework specialize and do what it does best. I don't
expect the existing framework teams to embrace this idea. There will
always be new features introduced to them. There will always be
features in Siege that none of the others will have. That's the nature
of the beast.&lt;/p&gt;
&lt;p&gt;But my goal is to give you more options and to not take any away. I
hope that clears up any confusion around what the intent is here.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Happy coding!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=A+philosophical+discussion+about+Inversion+of+Control+frameworks&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2010%2f01%2f10%2fa-philosophical-discussion-about-inversion-of-control-frameworks.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2010%2f01%2f10%2fa-philosophical-discussion-about-inversion-of-control-frameworks.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=46948" width="1" height="1"&gt;</content><author><name>mbratton</name><uri>http://www.lostechies.com/members/mbratton/default.aspx</uri></author><category term="Siege" scheme="http://www.lostechies.com/blogs/marcus_bratton/archive/tags/Siege/default.aspx" /><category term="IoC" scheme="http://www.lostechies.com/blogs/marcus_bratton/archive/tags/IoC/default.aspx" /></entry><entry><title>Introducing Siege.ServiceLocation.Extensions: FactoryMethod Support, Dependency Resolution based on type injected into added</title><link rel="alternate" type="text/html" href="/blogs/marcus_bratton/archive/2009/12/27/introducing-siege-servicelocation-extensions-factorymethod-support-dependency-resolution-based-on-type-injected-into-added.aspx" /><id>/blogs/marcus_bratton/archive/2009/12/27/introducing-siege-servicelocation-extensions-factorymethod-support-dependency-resolution-based-on-type-injected-into-added.aspx</id><published>2009-12-27T17:43:00Z</published><updated>2009-12-27T17:43:00Z</updated><content type="html">&lt;h3&gt;Introduction&lt;/h3&gt;
&lt;p&gt;For anyone wanting to follow The Siege Project, I routinely post updates on twitter (MarcusTheBold). Feel free to follow.&lt;/p&gt;
&lt;p&gt;I did some refactoring and clean up. I'll address the specifics in a moment. First, I'll list the files for download for anyone interested:&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Siege.ServiceLocation library&lt;/b&gt;:&lt;/p&gt;
&lt;p&gt;&lt;a title="Siege.ServiceLocation.zip" href="http://cloud.github.com/downloads/MarcusTheBold/Siege/Siege.ServiceLocation.zip"&gt;Siege.ServiceLocation.zip&lt;/a&gt;&lt;br /&gt;&lt;a title="Siege.ServiceLocation.zip" href="http://cloud.github.com/downloads/MarcusTheBold/Siege/Siege.ServiceLocation.Extensions.zip"&gt;Siege.ServiceLocation.Extensions.zip&lt;br /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;ASP.NET MVC Integration&lt;/b&gt;:&lt;/p&gt;
&lt;p&gt;&lt;a title="Siege.ServiceLocation.HttpIntegration.zip" href="http://cloud.github.com/downloads/MarcusTheBold/Siege/Siege.ServiceLocation.HttpIntegration.zip"&gt;Siege.ServiceLocation.HttpIntegration.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;IoC Framework Adapters&lt;/b&gt;:&lt;/p&gt;
&lt;p&gt;&lt;a title="Siege.ServiceLocation.AutofacAdapter.zip" href="http://cloud.github.com/downloads/MarcusTheBold/Siege/Siege.ServiceLocation.AutofacAdapter.zip"&gt;Siege.ServiceLocation.AutofacAdapter.zip&lt;/a&gt;     &lt;br /&gt;&lt;a title="Siege.ServiceLocation.NinjectAdapter.zip" href="http://cloud.github.com/downloads/MarcusTheBold/Siege/Siege.ServiceLocation.NinjectAdapter.zip"&gt;Siege.ServiceLocation.NinjectAdapter.zip&lt;/a&gt;     &lt;br /&gt;&lt;a title="Siege.ServiceLocation.StructureMapAdapter.zip" href="http://cloud.github.com/downloads/MarcusTheBold/Siege/Siege.ServiceLocation.StructureMapAdapter.zip"&gt;Siege.ServiceLocation.StructureMapAdapter.zip&lt;/a&gt;     &lt;br /&gt;&lt;a title="Siege.ServiceLocation.UnityAdapter.zip" href="http://cloud.github.com/downloads/MarcusTheBold/Siege/Siege.ServiceLocation.UnityAdapter.zip"&gt;Siege.ServiceLocation.UnityAdapter.zip&lt;/a&gt;     &lt;br /&gt;&lt;a title="Siege.ServiceLocation.WindsorAdapter.zip" href="http://cloud.github.com/downloads/MarcusTheBold/Siege/Siege.ServiceLocation.WindsorAdapter.zip"&gt;Siege.ServiceLocation.WindsorAdapter.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Quick Start&lt;/b&gt;:&lt;/p&gt;
&lt;p&gt;&lt;a title="SiegeMVCQuickStart.zip" href="http://cloud.github.com/downloads/MarcusTheBold/Siege/SiegeMVCQuickStart.zip"&gt;SiegeMVCQuickStart.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;A few people have asked me about contributing and extending the Siege.ServiceLocation library. My preference is to keep the Siege.ServiceLocation namespace itself as the main engine for enabling a wide variety of syntaxes and not grow the default syntax beyond what comes pre-packaged (the given-when-then syntax). However, I do want the project to grow and expand to meet the needs of anyone that uses it. Therefore, I've added a new project to the Siege.ServiceLocation umbrella: Siege.ServiceLocation.Extensions&lt;/p&gt;
&lt;p&gt;Users can download this as an optional library that works in conjunction with Siege.ServiceLocation. Contributors can contribute to this library to create new syntax and new use cases to enable users to solve problems. The only restrictions I will put on this is that it should only reference Siege.ServiceLocation and not any particular IoC or external framework. If you want to integrate with a specific IoC, or another specific framework, I do encourage you to do so -- only in a seperate project. I want to make sure that people consuming this framework don't have to add dependencies to frameworks and systems they do not intend to use.&lt;/p&gt;
&lt;p&gt;As these particular cases come up we will address them as necessary.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;So what changed?&lt;/h3&gt;
&lt;p&gt;Not a whole lot. There were some assumptions in the system around conditions and how they were evaluated that I changed to defer through an implementation via interface. What that means is that anyone extending the framework can now determine on their own how a conditions should be determined as valid for a particular use case rather than explicitly comparing against context. Additionally, I extended the framework to track the types it has been resolving. Finally, I simplified some interfaces, particularly around supporting new IoC containers. I expect that I will make a few more modifications before releasing a 1.0 version -- the execution context is a primary candidate, as right now it is fairly immature in it's implementation. The other change I anticipate is to enable the IoC to work with other cross-cutting steps during resolution. Specifically, I've been working on incorporating AOP support into Siege.ServiceLocation and it's almost complete, but I'm still pondering how to incorporate it. It may require a slight refactory, it may not. We'll see.&lt;/p&gt;
&lt;p&gt;Once I have made these two changes I expect I'll do a feature freeze for Siege.ServiceLocation and release it as a 1.0 version.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;New Features in Siege.ServiceLocation.Extensions&lt;/h3&gt;
&lt;p&gt;Included already in this project are two new types of usages: Factory Methods and the ability to resolve dependencies based on the resolution hierarchy. That is to say, you can conditionally specify types to be used when the container has already decided to use other types. As always, you can additionally refer to the unit tests for detailed examples.&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration: underline;"&gt;&lt;br /&gt;Factory Methods:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;You can now specify a factory method to be used when constructing an object, both by default or when a condition is met. This works nearly identically to your standard Given-When-Then functionality, except instead of "Then" you use "ConstructWith", making it a Given-ConstructWith or Given-When-ConstructWith syntax.&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration: underline;"&gt;&lt;br /&gt;Type Resolution based on parent types&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I'm not really sure what to call this. The syntax is like this - Given&amp;lt;BaseType&amp;gt;.WhenInjectingInto&amp;lt;ParentType&amp;gt;.Then&amp;lt;ImplementingType&amp;gt;. Basically it works like this: if you have 'BaseType1' which has a constructor dependency 'IDependency' and is implemented by 'TypeA' and 'TypeB', you can say "When you decide to resolve as 'TypeA', use the 'DependencyA' implementation of 'IDependency', otherwise use the default (if one is specified)."&lt;/p&gt;
&lt;p&gt;By combining this with normal contextual resolution, you can set up rules for your types to be resolved based on arbitrary context and for their dependencies to be resolved either based on arbitrary context as well, or resolved based on which type is currently being resolved, or a combination thereof. It is important to note that when you specify multiple satisfiable criteria for resolution -- for example arbitrary context that is satisfied AND resolution based on a type being resolved that is ALSO true, the system will choose the first applicable use case (the first one registered). Additionally, factory method support is compatible with the aforementioned case of resolving dependencies based on the parent's type. You can tell it to use a factory when the 'WhenInjectionInto&amp;lt;T&amp;gt;' scenario is satisfied. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;In Closing&lt;/h3&gt;
&lt;p&gt;The goal with this system was to be able to quickly and easily extend it to support new syntaxes and usages. When I added these new syntaxes, each of them took me roughly 30 minutes from beginning to all tests passing at the end. While I am the author of this system, I expect that the barrier for other users would not be too much higher given a very basic understanding of the interfaces involved. For example, the amount of code to support Factory Methods was maybe all told about 100 lines of code between syntax and implementation while the amount of code to support dependency resolution based on the type its injected into was less than 150 lines.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Until next time, Happy Coding!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Introducing+Siege.ServiceLocation.Extensions%3a+FactoryMethod+Support%2c+Dependency+Resolution+based+on+type+injected+into+added&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2009%2f12%2f27%2fintroducing-siege-servicelocation-extensions-factorymethod-support-dependency-resolution-based-on-type-injected-into-added.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2009%2f12%2f27%2fintroducing-siege-servicelocation-extensions-factorymethod-support-dependency-resolution-based-on-type-injected-into-added.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=43456" width="1" height="1"&gt;</content><author><name>mbratton</name><uri>http://www.lostechies.com/members/mbratton/default.aspx</uri></author><category term="Siege" scheme="http://www.lostechies.com/blogs/marcus_bratton/archive/tags/Siege/default.aspx" /><category term="IoC" scheme="http://www.lostechies.com/blogs/marcus_bratton/archive/tags/IoC/default.aspx" /></entry><entry><title>Added support for Unity, Autofac to Siege.ServiceLocation</title><link rel="alternate" type="text/html" href="/blogs/marcus_bratton/archive/2009/12/23/added-support-for-unity-autofac-to-siege-servicelocation.aspx" /><id>/blogs/marcus_bratton/archive/2009/12/23/added-support-for-unity-autofac-to-siege-servicelocation.aspx</id><published>2009-12-23T17:23:00Z</published><updated>2009-12-23T17:23:00Z</updated><content type="html">&lt;p&gt;&amp;hellip;plus, some other house-cleaning items.&lt;/p&gt;
&lt;p&gt;Last night I put together adapters for Autofac and Unity. The process turned out to be rather straightforward; I think all told for both it took me about an hour from adding the projects to all tests passing. I may have a final tweak for this project around how adapters work &amp;ndash; there is one method that I think doesn&amp;rsquo;t need to be placed where it is, so I&amp;rsquo;ll probably move it. After that, I don&amp;rsquo;t anticipate many (if any) major changes to how it works &amp;hellip; I&amp;rsquo;ll just put out a Siege.ServiceLocation.Extensions project to house more things (an auto-register, factory method support, things like that). It&amp;rsquo;ll be a good chance to prove out how extensible this really is.&lt;/p&gt;
&lt;p&gt;Other than that I did some tweaks to namespaces to bring everything into one common scheme for namespacing. Nothing new beyond those items; I updated all the downloadable items with the latest versions. Here are the links:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Siege.ServiceLocation library&lt;/b&gt;:&lt;/p&gt;
&lt;p&gt;&lt;a title="Siege.ServiceLocation.zip" href="http://cloud.github.com/downloads/MarcusTheBold/Siege/Siege.ServiceLocation.zip"&gt;Siege.ServiceLocation.zip&lt;/a&gt;     &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;ASP.NET MVC Integration&lt;/b&gt;:&lt;/p&gt;
&lt;p&gt;&lt;a title="Siege.ServiceLocation.HttpIntegration.zip" href="http://cloud.github.com/downloads/MarcusTheBold/Siege/Siege.ServiceLocation.HttpIntegration.zip"&gt;Siege.ServiceLocation.HttpIntegration.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;IoC Framework Adapters&lt;/b&gt;:&lt;/p&gt;
&lt;p&gt;&lt;a title="Siege.ServiceLocation.AutofacAdapter.zip" href="http://cloud.github.com/downloads/MarcusTheBold/Siege/Siege.ServiceLocation.AutofacAdapter.zip"&gt;Siege.ServiceLocation.AutofacAdapter.zip&lt;/a&gt;     &lt;br /&gt;&lt;a title="Siege.ServiceLocation.NinjectAdapter.zip" href="http://cloud.github.com/downloads/MarcusTheBold/Siege/Siege.ServiceLocation.NinjectAdapter.zip"&gt;Siege.ServiceLocation.NinjectAdapter.zip&lt;/a&gt;     &lt;br /&gt;&lt;a title="Siege.ServiceLocation.StructureMapAdapter.zip" href="http://cloud.github.com/downloads/MarcusTheBold/Siege/Siege.ServiceLocation.StructureMapAdapter.zip"&gt;Siege.ServiceLocation.StructureMapAdapter.zip&lt;/a&gt;     &lt;br /&gt;&lt;a title="Siege.ServiceLocation.UnityAdapter.zip" href="http://cloud.github.com/downloads/MarcusTheBold/Siege/Siege.ServiceLocation.UnityAdapter.zip"&gt;Siege.ServiceLocation.UnityAdapter.zip&lt;/a&gt;     &lt;br /&gt;&lt;a title="Siege.ServiceLocation.WindsorAdapter.zip" href="http://cloud.github.com/downloads/MarcusTheBold/Siege/Siege.ServiceLocation.WindsorAdapter.zip"&gt;Siege.ServiceLocation.WindsorAdapter.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Quick Start&lt;/b&gt;:&lt;/p&gt;
&lt;p&gt;&lt;a title="SiegeMVCQuickStart.zip" href="http://cloud.github.com/downloads/MarcusTheBold/Siege/SiegeMVCQuickStart.zip"&gt;SiegeMVCQuickStart.zip&lt;/a&gt;     &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For convenience the main library is bundled with the HttpIntegration zip as well as each of the Adapter zip files.&lt;/p&gt;
&lt;p&gt;Have a Happy Holidays!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Added+support+for+Unity%2c+Autofac+to+Siege.ServiceLocation&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2009%2f12%2f23%2fadded-support-for-unity-autofac-to-siege-servicelocation.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2009%2f12%2f23%2fadded-support-for-unity-autofac-to-siege-servicelocation.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=42026" width="1" height="1"&gt;</content><author><name>mbratton</name><uri>http://www.lostechies.com/members/mbratton/default.aspx</uri></author><category term="Siege" scheme="http://www.lostechies.com/blogs/marcus_bratton/archive/tags/Siege/default.aspx" /><category term="IoC" scheme="http://www.lostechies.com/blogs/marcus_bratton/archive/tags/IoC/default.aspx" /></entry><entry><title>The Siege Project: Siege.ServiceLocation Part 5 – A guide to getting started with Siege.ServiceLocation</title><link rel="alternate" type="text/html" href="/blogs/marcus_bratton/archive/2009/12/18/the-siege-project-siege-servicelocation-part-5-a-guide-to-getting-started-with-siege-servicelocation.aspx" /><id>/blogs/marcus_bratton/archive/2009/12/18/the-siege-project-siege-servicelocation-part-5-a-guide-to-getting-started-with-siege-servicelocation.aspx</id><published>2009-12-18T06:24:00Z</published><updated>2009-12-18T06:24:00Z</updated><content type="html">&lt;h3&gt;The Siege Project &lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/06/introducing-siege.aspx"&gt;Introduction&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/06/the-siege-project-siege-servicelocation.aspx"&gt;Siege.ServiceLocation Part 1 - Introduction and General Use&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/09/the-siege-project-siege-servicelocation-part-2-contextual-registration-and-resolution.aspx" target="_blank"&gt;Siege.ServiceLocation Part 2 &amp;ndash; Contextual Registration and Resolution&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/10/the-siege-project-siege-servicelocation-part-3-extending-the-container-with-custom-use-cases.aspx" target="_blank"&gt;Siege.ServiceLocation Part 3 &amp;ndash; Extending the container with custom use cases&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/18/the-siege-project-siege-servicelocation-part-4-integrating-siege-servicelocation-with-asp-net-mvc.aspx" target="_blank"&gt;Siege.ServiceLocation Part 4 &amp;ndash; Integrating Siege.ServiceLocation with ASP.NET MVC&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Siege.ServiceLocation Part 5 &amp;ndash; A guide to getting started with Siege.ServiceLocation &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;The Quick Start&lt;/h3&gt;
&lt;p&gt;I&amp;rsquo;ve put together a quickstart project. You can look through the files in this project to see how everything is put together. You can get the quick start project here:&lt;/p&gt;
&lt;p&gt;&lt;a title="http://cloud.github.com/downloads/MarcusTheBold/Siege/SiegeMVCQuickStart.zip" href="http://cloud.github.com/downloads/MarcusTheBold/Siege/SiegeMVCQuickStart.zip"&gt;http://cloud.github.com/downloads/MarcusTheBold/Siege/SiegeMVCQuickStart.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Things to look at in this project:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Global.asax.cs &amp;ndash; uses SiegeHttpApplication and shows how to hook up your ServiceLocatorAdapter (the quickstart uses Ninject) and shows where to configure the SiegeContainer.&lt;/li&gt;
&lt;li&gt;ServiceLocatorExtensions.cs &amp;ndash; shows how to do registrations with the SiegeContainer, both default and contextual. Also, shows how to do context on a variety of conditions, and shows how to register pre-configured instances with the UserFinder class.&lt;/li&gt;
&lt;li&gt;AccountController &amp;ndash; contrived, but shows an example of to work with IContextStore&lt;/li&gt;
&lt;li&gt;The other controllers/services &amp;ndash; basic classes that build up how the app works together&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This is a purely contrived app that doesn&amp;rsquo;t really do anything. There are 4 users &amp;ndash; Webmaster, AdminUser, TrialUser and PaidUser. For all accounts, the password is pass123. As you login as different users you should see things start happening contextually based on attributes associated with the particular user you are associated with. The different views have text explaining how they work and what to expect. &lt;/p&gt;
&lt;p&gt;Hopefully this will give a concrete example of how things work together. As always, if you have questions, feel free to leave a comment and I will respond.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Happy coding!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=The+Siege+Project%3a+Siege.ServiceLocation+Part+5+%e2%80%93+A+guide+to+getting+started+with+Siege.ServiceLocation&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2009%2f12%2f18%2fthe-siege-project-siege-servicelocation-part-5-a-guide-to-getting-started-with-siege-servicelocation.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2009%2f12%2f18%2fthe-siege-project-siege-servicelocation-part-5-a-guide-to-getting-started-with-siege-servicelocation.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=39684" width="1" height="1"&gt;</content><author><name>mbratton</name><uri>http://www.lostechies.com/members/mbratton/default.aspx</uri></author><category term="Siege" scheme="http://www.lostechies.com/blogs/marcus_bratton/archive/tags/Siege/default.aspx" /><category term="IoC" scheme="http://www.lostechies.com/blogs/marcus_bratton/archive/tags/IoC/default.aspx" /><category term="MVC" scheme="http://www.lostechies.com/blogs/marcus_bratton/archive/tags/MVC/default.aspx" /></entry><entry><title>The Siege Project: Siege.ServiceLocation, Part 4 – Integrating Siege.ServiceLocation with ASP.NET MVC</title><link rel="alternate" type="text/html" href="/blogs/marcus_bratton/archive/2009/12/18/the-siege-project-siege-servicelocation-part-4-integrating-siege-servicelocation-with-asp-net-mvc.aspx" /><id>/blogs/marcus_bratton/archive/2009/12/18/the-siege-project-siege-servicelocation-part-4-integrating-siege-servicelocation-with-asp-net-mvc.aspx</id><published>2009-12-18T05:10:00Z</published><updated>2009-12-18T05:10:00Z</updated><content type="html">&lt;h3&gt;The Siege Project &lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/06/introducing-siege.aspx"&gt;Introduction&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/06/the-siege-project-siege-servicelocation.aspx"&gt;Siege.ServiceLocation Part 1 - Introduction and General Use&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/09/the-siege-project-siege-servicelocation-part-2-contextual-registration-and-resolution.aspx" target="_blank"&gt;Siege.ServiceLocation Part 2 &amp;ndash; Contextual Registration and Resolution&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/10/the-siege-project-siege-servicelocation-part-3-extending-the-container-with-custom-use-cases.aspx" target="_blank"&gt;Siege.ServiceLocation Part 3 &amp;ndash; Extending the container with custom use cases&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Siege.ServiceLocation Part 4 &amp;ndash; Integrating Siege.ServiceLocation with ASP.NET MVC &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/18/the-siege-project-siege-servicelocation-part-5-a-guide-to-getting-started-with-siege-servicelocation.aspx"&gt;Siege.ServiceLocation Part 5 &amp;ndash; A guide to getting started with Siege.ServiceLocation&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Get the library used to integrate with ASP.NET MVC by downloading the binaries here: &lt;a title="http://cloud.github.com/downloads/MarcusTheBold/Siege/Siege.ServiceLocation.HttpIntegration.zip" href="http://cloud.github.com/downloads/MarcusTheBold/Siege/Siege.ServiceLocation.HttpIntegration.zip"&gt;http://cloud.github.com/downloads/MarcusTheBold/Siege/Siege.ServiceLocation.HttpIntegration.zip&lt;/a&gt;     &lt;br /&gt;Alternatively, you can get the source code here: &lt;a title="http://github.com/MarcusTheBold/Siege" href="http://github.com/MarcusTheBold/Siege"&gt;http://github.com/MarcusTheBold/Siege&lt;/a&gt; &lt;/p&gt;
&lt;h3&gt;&amp;nbsp;&lt;/h3&gt;
&lt;h3&gt;Combining Siege.ServiceLocation and ASP.NET MVC&lt;/h3&gt;
&lt;p&gt;By combining Siege.ServiceLocation with ASP.NET MVC, everything starts to come together. You get more than just the ability to abstract away your dependency on an individual IoC framework (and thereby allowing you to change implementations at the drop of a hat), you get the ability to react to changing conditions in your application and the individual user sessions. When resolving controllers, you have the ability to use views linked to either the contextually resolved controller, or linked to the base type that was requested. Integrating these two frameworks, it turns out, is incredibly simple to do.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;SiegeHttpApplication&lt;/h3&gt;
&lt;p&gt;SiegeHttpApplication is the main component that enables you to integrate with ASP.NET MVC. Inherit your Global application in the Global.asax.cs file from this class in order to turn your regular ASP.NET MVC application into a Siege enabled application. This abstract class forces you to implement only a handful of methods and offers you the ability to override several others (not actual implementation).&lt;/p&gt;
&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;" id="codeSnippet"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;abstract&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; SiegeHttpApplication : HttpApplication&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; IContextualServiceLocator ServiceLocator;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;abstract&lt;/span&gt; IServiceLocatorAdapter GetServiceLocatorAdapter();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; RegisterRoutes(RouteCollection routes) { }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;virtual&lt;/span&gt; IContextStore GetContextStore()&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; OnApplicationStarted()&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; OnApplicationStopped()&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; OnApplicationError(Exception exception)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The only method you must implement is GetServiceLocatorAdapter(). This instructs the SiegeHttpApplication what underlying IoC framework you wish to use. Other than this method, you have the ability to override the default IContextStore used by the SiegeContainer (by default the HttpSessionStore is used). OnApplicationStarted, OnApplicationStopped and OnApplicationError give you extension points to provide additional logic by which you can add custom logic for your own application.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;HttpSessionStore&lt;/h3&gt;
&lt;p&gt;By default, SiegeHttpApplication uses an implementation of IContextStore with the SiegeContainer called HttpSessionStore. This class stores items on the session of the user navigating your website, allowing you to control resolution on a user-by-user basis over the life of the user session. Developers can change this to any other implementation of IContextStore &amp;ndash; GlobalContextStore to make your entire application change implementations based on context (for responding to global conditions) or to a custom implementation, if you need finer control over how context is stored and used in the resolution process.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;And that&amp;rsquo;s it!&lt;/h3&gt;
&lt;p&gt;That&amp;rsquo;s all it takes to use Siege.ServiceLocation with ASP.NET MVC. I have put together a quick start application that shows in detail how all these parts work together. &lt;/p&gt;
&lt;p&gt;Happy Coding!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=The+Siege+Project%3a+Siege.ServiceLocation%2c+Part+4+%e2%80%93+Integrating+Siege.ServiceLocation+with+ASP.NET+MVC&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2009%2f12%2f18%2fthe-siege-project-siege-servicelocation-part-4-integrating-siege-servicelocation-with-asp-net-mvc.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2009%2f12%2f18%2fthe-siege-project-siege-servicelocation-part-4-integrating-siege-servicelocation-with-asp-net-mvc.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=39670" width="1" height="1"&gt;</content><author><name>mbratton</name><uri>http://www.lostechies.com/members/mbratton/default.aspx</uri></author><category term="Siege" scheme="http://www.lostechies.com/blogs/marcus_bratton/archive/tags/Siege/default.aspx" /><category term="IoC" scheme="http://www.lostechies.com/blogs/marcus_bratton/archive/tags/IoC/default.aspx" /><category term="MVC" scheme="http://www.lostechies.com/blogs/marcus_bratton/archive/tags/MVC/default.aspx" /></entry><entry><title>The Siege Project: Siege.ServiceLocation, Part 3 – Extending the container with custom use cases</title><link rel="alternate" type="text/html" href="/blogs/marcus_bratton/archive/2009/12/10/the-siege-project-siege-servicelocation-part-3-extending-the-container-with-custom-use-cases.aspx" /><id>/blogs/marcus_bratton/archive/2009/12/10/the-siege-project-siege-servicelocation-part-3-extending-the-container-with-custom-use-cases.aspx</id><published>2009-12-11T04:32:00Z</published><updated>2009-12-11T04:32:00Z</updated><content type="html">&lt;h3&gt;&lt;b&gt;The Siege Project&lt;/b&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/06/introducing-siege.aspx"&gt;Introduction&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/06/the-siege-project-siege-servicelocation.aspx"&gt;Siege.ServiceLocation Part 1 - Introduction and General Use&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/09/the-siege-project-siege-servicelocation-part-2-contextual-registration-and-resolution.aspx"&gt;Siege.ServiceLocation Part 2 &amp;ndash; Contextual Registration and Resolution&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Siege.ServiceLocation Part 3 &amp;ndash; Extending the container with custom use cases &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/18/the-siege-project-siege-servicelocation-part-4-integrating-siege-servicelocation-with-asp-net-mvc.aspx"&gt;Siege.ServiceLocation Part 4 &amp;ndash; Integrating Siege.ServiceLocation with ASP.NET MVC&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/18/the-siege-project-siege-servicelocation-part-5-a-guide-to-getting-started-with-siege-servicelocation.aspx"&gt;Siege.ServiceLocation Part 5 &amp;ndash; A guide to getting started with Siege.ServiceLocation&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;&lt;b&gt;Adding new functionality to the container without having to change Siege.ServiceLocation&lt;/b&gt;&lt;/h3&gt;
&lt;p&gt;When I started this project, I had a few main goals in mind. I wanted to be able to register things with a straightforward and simple syntax. I wanted to be able to use any IoC framework to do the heavy lifting of type resolution for me. I wanted to be able to resolve multiple different types straight out of the container when state changed. And finally, I wanted to be able to extend it without having to constantly update the framework and put out a new release.&lt;/p&gt;
&lt;p&gt;This post shows how I do it. &lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m going to throw a lot at you guys in short order. I&amp;rsquo;ll do my best to keep it simple and make it understandable. While simplicity has been my goal overall for this whole library, this is going to be the most involved aspect of the system. It&amp;rsquo;s not bad, I promise. The interfaces are small and the amount of code you have to implement is minimal. But there&amp;rsquo;s a few types that come into play. I&amp;rsquo;ll take the time to explain each one as we go and try to draw a simplified picture of how they work together. If anything is confusing or not clear, please reply in the comments and I&amp;rsquo;ll do my best to explain. If it&amp;rsquo;s a big topic, I&amp;rsquo;ll put up another post to go over that piece. &lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s hit the code.&lt;/p&gt;
&lt;h3&gt;&lt;b&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;h3&gt;&lt;b&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;h3&gt;&lt;b&gt;How use cases work&lt;/b&gt;&lt;/h3&gt;
&lt;p&gt;As I&amp;rsquo;ve mentioned in previous posts, use cases are specific implementations of the IUseCase interface. Let&amp;rsquo;s take a look at the interface.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; font-size: 8pt; cursor: text;"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;interface&lt;/span&gt; IUseCase&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    Type GetBoundType();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    Type GetUseCaseBindingType();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; Resolve(IInstanceResolver locator, IList&amp;lt;&lt;span style="color: #0000ff;"&gt;object&lt;/span&gt;&amp;gt; context);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; Resolve(IInstanceResolver locator);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;bool&lt;/span&gt; IsValid(IList&amp;lt;&lt;span style="color: #0000ff;"&gt;object&lt;/span&gt;&amp;gt; context);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;As you can see, there are a handful of methods that are required by this interface. Let&amp;rsquo;s go through them real quick.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;GetBoundType() &amp;ndash; this function is used by the SiegeContainer to determine the type that this particular instance of your use case is using. For example, when you do a registration like Give&amp;lt;IFoo&amp;gt;.Then&amp;lt;Foo&amp;gt;(), you get back an instance of DefaultUseCase&amp;lt;Foo&amp;gt;. When you call GetBoundType(), you will get the Foo type. &lt;/li&gt;
&lt;li&gt;Resolve() &amp;ndash; This method allows you to control exactly how items are resolved. &lt;/li&gt;
&lt;li&gt;IsValid() &amp;ndash; This method returns true if a use case is applicable according to context &amp;ndash; false if it is not. &lt;/li&gt;
&lt;li&gt;GetUseCaseBinding() &amp;ndash; This returns a type (assumed to be an implementation of IUseCaseBinding) which is used to register use cases. &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;IInstanceResolver is one of the interfaces that IServiceLocator and IServiceLocatorAdapter inherit from.&amp;nbsp; As the name implies, it resolves instances. &lt;/p&gt;
&lt;div id="codeSnippetWrapper" style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; font-size: 8pt; cursor: text;"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;interface&lt;/span&gt; IInstanceResolver&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; GetInstance(Type type, &lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; key);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; GetInstance(Type type);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In most cases you can inherit from the abstract type GenericUseCase&amp;lt;T&amp;gt;, which only forces you to implement the method GetUseCaseBinding() and manages all the other methods for you (you can of course override any you feel are necessary). All use case bindings are implementations of IUseCaseBinding, which looks like this:&lt;/p&gt;
&lt;div id="codeSnippetWrapper" style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; font-size: 8pt; cursor: text;"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;interface&lt;/span&gt; IUseCaseBinding&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; Bind(IUseCase useCase);   &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Packaged with Siege.ServiceLocation are three use case binding types: IDefaultUseCaseBinding, IConditionalUseCaseBinding and IKeyBasedUseCaseBinding (used for registering and resolving by a particular string key). These binding types are in turn implemented by each of the adapters so that the use cases can be supported by the underlying IoC provider.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;It is important to note that if you create a new type of IUseCaseBinding you will need to write concrete implementations for whatever adapter you intend to use. Custom implementations of IUseCase that use one of the bundled use case bindings do not need to do this. Only create new IUseCaseBinding types if you have specialized instructions for how you want to register and/or resolve with a specific IoC provider.&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Custom types of bindings integrate easily with the container to provide seamless support for your new use case and binding. To do this, simple use the provided method on the SiegeContainer before you do your registrations:&lt;/p&gt;
&lt;div id="codeSnippetWrapper" style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; font-size: 8pt; cursor: text;"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;IServiceLocator AddBinding(Type baseBinding, Type targetBinding);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s take a look at a specific example.&lt;/p&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;h3&gt;Putting it all together &lt;/h3&gt;
&lt;p&gt;For this example, I am using Sean Chamber&amp;rsquo;s &lt;a target="_blank" href="http://www.lostechies.com/blogs/sean_chambers/archive/2008/11/16/ptom-the-decorator-pattern.aspx"&gt;implementation of the decorator pattern&lt;/a&gt; as a reference point. This example will show you how to extend the container to conditionally decorate types based on runtime conditions. Bear in mind that this example is highly contrived and exists solely for the purpose of demonstration. I will be using the Ninject framework as a support for this post. All source code (including examples for all three containers) is included in the unit tests project in the source code, which is found &lt;a target="_blank" href="http://github.com/MarcusTheBold/Siege"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;First, let&amp;rsquo;s look at the syntax to register types with decorators.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; font-size: 8pt; cursor: text;"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;locator&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    .AddBinding(&lt;span style="color: #0000ff;"&gt;typeof&lt;/span&gt;(IDecoratorUseCaseBinding&amp;lt;&amp;gt;), &lt;span style="color: #0000ff;"&gt;typeof&lt;/span&gt;(DecoratorUseCaseBinding&amp;lt;&amp;gt;))&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    .Register(Given&amp;lt;ICoffee&amp;gt;.Then&amp;lt;Coffee&amp;gt;())&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    .Register(Given&amp;lt;ICoffee&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;                  .When&amp;lt;Ingredients&amp;gt;(ingredients =&amp;gt; ingredients == Ingredients.WhippedCream)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;                  .DecorateWith&amp;lt;WhippedCreamDecorator&amp;gt;())&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    .Register(Given&amp;lt;ICoffee&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;                  .When&amp;lt;Ingredients&amp;gt;(ingredients =&amp;gt; ingredients == Ingredients.Espresso)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;                  .DecorateWith&amp;lt;EspressoShotDecorator&amp;gt;());&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Right off the bat you should see that I&amp;rsquo;m adding a custom binding, letting the framework know that when use cases specify IDecoratorUseCaseBinding&amp;lt;T&amp;gt; as their binding type to use DecoratorUseCaseBinding&amp;lt;T&amp;gt; as the implementation. This is one of the key parts of extending the container to support your custom registration.&amp;nbsp; &lt;/p&gt;
&lt;div id="codeSnippetWrapper" style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; font-size: 8pt; cursor: text;"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; DecoratorUseCaseBinding&amp;lt;TService&amp;gt; : IDecoratorUseCaseBinding&amp;lt;TService&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;private&lt;/span&gt; IKernel kernel;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;private&lt;/span&gt; IServiceLocatorAdapter locator;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; DecoratorUseCaseBinding(IKernel kernel, IServiceLocatorAdapter locator)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.kernel = kernel;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.locator = locator;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; Bind(IUseCase useCase)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        Bind((IDecoratorUseCase&amp;lt;TService&amp;gt;)useCase);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; Resolve(Type typeToResolve, Type argumentType, &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; rootObject)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        &lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; parameterName = typeToResolve.GetConstructor(&lt;span style="color: #0000ff;"&gt;new&lt;/span&gt;[] {argumentType}).GetParameters().Where(parameter =&amp;gt; parameter.ParameterType == argumentType).First().Name;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; kernel.Get(typeToResolve, &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; ConstructorArgument(parameterName, rootObject));&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; Bind(IDecoratorUseCase&amp;lt;TService&amp;gt; useCase)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        kernel.Bind(useCase.GetBoundType()).ToSelf();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;As you can see, DecoratorUseCaseBinding includes instructions to the container on how to register your use case with Ninject. You&amp;rsquo;ll also notice that I included a function called Resolve() on this class. This isn&amp;rsquo;t required by the interface, but I decided to keep these instructions here for the sake of simplicity in this example. Because this scenario requires objects to be specially constructed, I ask Ninject to resolve a type and give it a type argument and value to use during construction when it resolves the requested type.&lt;/p&gt;
&lt;p&gt;The next thing you should notice about our registration is the presence of the DecorateWith&amp;lt;TDecorator&amp;gt; function. This is not included with the Siege.ServiceLocation project. I have made it up for this example. It looks like this:&lt;/p&gt;
&lt;div id="codeSnippetWrapper" style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; font-size: 8pt; cursor: text;"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; RegistrationExtensions&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;static&lt;/span&gt; IContextualServiceLocator serviceLocator;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; Initialize(IContextualServiceLocator locator)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        serviceLocator = locator;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;static&lt;/span&gt; IDecoratorUseCase&amp;lt;TDecorator&amp;gt; DecorateWith&amp;lt;TDecorator&amp;gt;(&lt;span style="color: #0000ff;"&gt;this&lt;/span&gt; IConditionalActivationRule rule)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        var decoratorUseCase = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; DecoratorUseCase&amp;lt;TDecorator&amp;gt;(serviceLocator);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        decoratorUseCase.BindTo(rule.GetBoundType());&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        decoratorUseCase.SetActivationRule(rule);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; decoratorUseCase;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;I decided to extend the existing registration rather than create a new class that builds instances of DecoratorUseCase. While there is nothing forcing any consumer to do this, I decided to do it so that I could leverage the existing functionality that creates rules to associate with the use case, and to show how you can bolt things on to the existing infrastructure.&lt;/p&gt;
&lt;p&gt;Finally, let&amp;rsquo;s take a look at DecoratorUseCase. This class inherits from GenericUseCase&amp;lt;T&amp;gt; and implements the IDecoratorUseCase&amp;lt;T&amp;gt; interface. It also overrides some functionality in GenericUseCase, which I will explain.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; font-size: 8pt; cursor: text;"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; DecoratorUseCase&amp;lt;TService&amp;gt; : GenericUseCase&amp;lt;TService&amp;gt;, IDecoratorUseCase&amp;lt;TService&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;private&lt;/span&gt; IContextualServiceLocator serviceLocator;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; DecoratorUseCase(IContextualServiceLocator serviceLocator)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.serviceLocator = serviceLocator;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;override&lt;/span&gt; Type GetUseCaseBindingType()&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;typeof&lt;/span&gt; (IDecoratorUseCaseBinding&amp;lt;&amp;gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;override&lt;/span&gt; IActivationStrategy GetActivationStrategy()&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; DecoratorActivationStrategy(serviceLocator, GetBoundType());&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; DecoratorActivationStrategy : IActivationStrategy&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        &lt;span style="color: #0000ff;"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;readonly&lt;/span&gt; IContextualServiceLocator serviceLocator;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        &lt;span style="color: #0000ff;"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;readonly&lt;/span&gt; Type decoratedType;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; DecoratorActivationStrategy(IContextualServiceLocator serviceLocator, Type decoratedType)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;            &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.serviceLocator = serviceLocator;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;            &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.decoratedType = decoratedType;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; Resolve(IInstanceResolver locator, IList&amp;lt;&lt;span style="color: #0000ff;"&gt;object&lt;/span&gt;&amp;gt; context)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;            var useCaseBinding = (IDecoratorUseCaseBinding)locator.GetInstance(&lt;span style="color: #0000ff;"&gt;typeof&lt;/span&gt;(IDecoratorUseCaseBinding&amp;lt;TService&amp;gt;));&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;            var decorators = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; List&amp;lt;Type&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;            var rootObject = locator.GetInstance(decoratedType);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;            &lt;span style="color: #0000ff;"&gt;foreach&lt;/span&gt; (IDecoratorUseCase useCase &lt;span style="color: #0000ff;"&gt;in&lt;/span&gt; serviceLocator.GetRegisteredUseCasesForType(decoratedType))&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;            {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;                &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt;(useCase.IsValid(context)) decorators.Add(useCase.GetDecoratorType());&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;            }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;            &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; GetInstance(useCaseBinding, rootObject, decoratedType, decorators);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        &lt;span style="color: #0000ff;"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; GetInstance(IDecoratorUseCaseBinding binding, &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; rootObject, Type encapsulatedType, IList&amp;lt;Type&amp;gt; decorators)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;            &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (decorators.Count == 0) &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; rootObject;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;            Type decorator = decorators[0];&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;            IList&amp;lt;Type&amp;gt; prunedDecoratorList = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; List&amp;lt;Type&amp;gt;(decorators);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;            prunedDecoratorList.RemoveAt(0);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;            &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; resolvedObject = binding.Resolve(decorator, encapsulatedType, rootObject);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;            &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; GetInstance(binding, resolvedObject, encapsulatedType, prunedDecoratorList);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; Type GetDecoratorType()&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;typeof&lt;/span&gt; (TService);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;As noted earlier, by using GenericUseCase we are only required to implement the GetUseCaseBindingType() function, which returns the IDecoratorUseCase&amp;lt;&amp;gt; type as its value. This is used by SiegeContainer during registration to find the type specified in the AddBinding statement and use it to direct the underlying IoC how to register your custom implementation of IUseCase. &lt;/p&gt;
&lt;p&gt;The GetActivationStrategy() function is overriden in this class to return a new type of IActivationStrategy. By default, GenericUseCase&amp;lt;T&amp;gt; uses a GenericActivationStrategy which simply calls GetInstance() on the IServiceLocatorAdapter. By overriding this and providing a new implementation, we are able to give the SiegeContainer high-level instructions on how to construct our object for this use case. The strategy checks all applicable use cases for the supplied context and gathers the appropriate decorator types, then recursively calls itself to build the object.&lt;/p&gt;
&lt;p&gt;This function calls back into the binding to do the ninject-specific type resolution, which specially constructs the object for me. When it&amp;rsquo;s all said and done, I have a fully decorated object in line with the context that has been added to my IContextStore. If I specify whipped cream, I get an instance of Coffee decorated with a WhippedCreamDecorator. If I specify espresso, I get an instance of Coffee decorated with an EspressoDecorator. If I specify both, I get an instance of Coffee decorated with both.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;By default SiegeContainer resolves types based on the first satisfied rule it encounters in the context, or it uses a default case. This example significantly changes how the container works by providing a mechanism for it to use ALL applicable context instead of only the first applicable context. &lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;So that&amp;rsquo;s how it works&lt;/h3&gt;
&lt;p&gt;Extending the library is probably the most complex usages of the this project, but I hope that it is not prohibitively so. It&amp;rsquo;s also a feature that I expect will not be used as much as everything else that the container does. I&amp;rsquo;m not sure how useful the community will find this; while I have been able to recognize areas this might apply at my company, the scope of where it would be useful is fairly narrow. Still, I think it is a nice feature and a good way to show how to extend a system without having to modify its internals. &lt;/p&gt;
&lt;p&gt;In the comments of the last post, a responder mentioned wanting to be able to use factory methods to construct objects depending on certain conditions being met. I believe that this feature enables that a developer to extend this project with that very functionality without having to go and update the project itself.&lt;/p&gt;
&lt;p&gt;I would like very much to hear feedback on what you guys think of this. Is it too hard? Is it too confusing? Is it useful?&lt;/p&gt;
&lt;p&gt;Until next time, Happy Coding!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=The+Siege+Project%3a+Siege.ServiceLocation%2c+Part+3+%e2%80%93+Extending+the+container+with+custom+use+cases&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2009%2f12%2f10%2fthe-siege-project-siege-servicelocation-part-3-extending-the-container-with-custom-use-cases.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2009%2f12%2f10%2fthe-siege-project-siege-servicelocation-part-3-extending-the-container-with-custom-use-cases.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=38745" width="1" height="1"&gt;</content><author><name>mbratton</name><uri>http://www.lostechies.com/members/mbratton/default.aspx</uri></author><category term="Siege" scheme="http://www.lostechies.com/blogs/marcus_bratton/archive/tags/Siege/default.aspx" /><category term="IoC" scheme="http://www.lostechies.com/blogs/marcus_bratton/archive/tags/IoC/default.aspx" /></entry><entry><title>The Siege Project: Siege.ServiceLocation, Part 2 - Contextual Registration and Resolution</title><link rel="alternate" type="text/html" href="/blogs/marcus_bratton/archive/2009/12/09/the-siege-project-siege-servicelocation-part-2-contextual-registration-and-resolution.aspx" /><id>/blogs/marcus_bratton/archive/2009/12/09/the-siege-project-siege-servicelocation-part-2-contextual-registration-and-resolution.aspx</id><published>2009-12-09T07:25:00Z</published><updated>2009-12-09T07:25:00Z</updated><content type="html">&lt;h3&gt;&lt;b&gt;The Siege Project&lt;/b&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/06/introducing-siege.aspx"&gt;Introduction&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/06/the-siege-project-siege-servicelocation.aspx"&gt;Siege.ServiceLocation Part 1 - Introduction and General Use&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Siege.ServiceLocation Part 2 &amp;ndash; Contextual Registration and Resolution &lt;/li&gt;
&lt;li&gt;&lt;a target="_blank" href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/10/the-siege-project-siege-servicelocation-part-3-extending-the-container-with-custom-use-cases.aspx"&gt;Siege.ServiceLocation Part 3 &amp;ndash; Extending the container with custom use cases &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/18/the-siege-project-siege-servicelocation-part-4-integrating-siege-servicelocation-with-asp-net-mvc.aspx"&gt;Siege.ServiceLocation Part 4 &amp;ndash; Integrating Siege.ServiceLocation with ASP.NET MVC&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/18/the-siege-project-siege-servicelocation-part-5-a-guide-to-getting-started-with-siege-servicelocation.aspx"&gt;Siege.ServiceLocation Part 5 &amp;ndash; A guide to getting started with Siege.ServiceLocation&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Some house cleaning items before we get started on this post.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You can download the source code to the currently published components here: &lt;a href="http://github.com/MarcusTheBold/Siege" title="http://github.com/MarcusTheBold/Siege"&gt;http://github.com/MarcusTheBold/Siege&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;You can download the binaries to the currently published components here: &lt;a href="http://github.com/MarcusTheBold/Siege/downloads" title="http://github.com/MarcusTheBold/Siege/downloads"&gt;http://github.com/MarcusTheBold/Siege/downloads&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;I&amp;rsquo;m working on picking out an OSS license. I hope to have one up soon. &lt;/li&gt;
&lt;li&gt;Some of the feedback I&amp;rsquo;ve received is to give examples of how to use this. I will put up a quick-start example in the near future and write a &amp;lsquo;getting started&amp;rsquo; blog post as well. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;&lt;b&gt;What is Contextual Registration?&lt;/b&gt;&lt;/h3&gt;
&lt;p&gt;Contextual Registration, simply put, is telling the SiegeContainer that there are certain criteria that have to be met in order for a certain type to resolved. These criteria are completely arbitrary and up to the user. Perhaps you only want to resolve a particular type if the user is a super user? Maybe you integrate with multiple 3rd party vendors for a particular service and want to resolve one based on data associated with the logged in user. Perhaps you want your system to serve up different types for different states of the app, to mock 3rd party integration points or to respond to a resource being unavailable. All of these scenarios are expressable with contextual registration. &lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Let&amp;rsquo;s look at the example I hinted at in my last post.&lt;/p&gt;
&lt;pre style="border: 1px solid #cecece; padding: 5px; overflow: auto; background-color: #fbfbfb; min-height: 40px; width: 97.5%;"&gt;&lt;pre style="margin: 0em; background-color: #fbfbfb; width: 100%;"&gt;locator.Register(&lt;span style="color: #2b91af;"&gt;Given&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;IOrderFulfillmentService&lt;/span&gt;&amp;gt;&lt;br /&gt;                            .When&amp;lt;&lt;span style="color: #2b91af;"&gt;VendorStatus&lt;/span&gt;&amp;gt;(status =&amp;gt; status == &lt;span style="color: #2b91af;"&gt;VendorStatus&lt;/span&gt;.Offline)&lt;br /&gt;                            .Then&amp;lt;&lt;span style="color: #2b91af;"&gt;DeferredOrderFulfillmentService&lt;/span&gt;&amp;gt;());&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;So what does this mean? Basically, there are a handful of implementations of IUseCase packaged with Siege.ServiceLocation. The two main ones are default use cases and conditional uses cases. When you do something like, Given&amp;lt;Interface&amp;gt;.Then&amp;lt;ConcreteType&amp;gt;(), you create a default use case for the locator to use when none of the conditional use cases are satisfied.&lt;/p&gt;
&lt;p&gt;When you use the above registration, the locator registers the type with the underlying adapter and tracks the conditions around the resolution. The literal translation of this registration is &amp;ldquo;When I ask for an instance of IOrderFulfillmentService, check to see if the vendor is offline. If it is, give me an instance of DeferredOrderFulfillmentService. If not, return me the default (if one is defined).&amp;rdquo; Using this, you can set up behaviors in your system that are tracked by the locator and resolved in your system as context begins to apply.&lt;/p&gt;
&lt;p&gt;Where I work, we use contextual registration as a way to augment our default registrations in one of our systems, which come in the form of a pre-wired container. We change the look and feel of the website based on attributes associated with the user that is logged in. We accomplish this in large part by using contextual registration. This has been useful for us in helping to avoid having to write additional conditional logic to determine how to deliver the user experience based on data points associated with the person that is logged in.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;Tracking Context for the SiegeContainer&lt;/h3&gt;
&lt;p&gt;Contextual Registration is all good and well but at the end of the day your application needs to be able to determine what types to resolve during its execution. To do this, The SiegeContainer class uses an interface called IContextStore. This interface defines how the SiegeContainer interacts with whatever underlying mechanism you decide to use to track context in your application. By default, when you instantiate a SiegeContainer, it uses an implementation called GlobalContextStore.&lt;/p&gt;
&lt;pre style="border: 1px solid #cecece; padding: 5px; overflow: auto; background-color: #fbfbfb; min-height: 40px; width: 97.5%;"&gt;&lt;pre style="margin: 0em; background-color: #fbfbfb; width: 100%;"&gt;&lt;span style="color: #0000ff;"&gt;public &lt;/span&gt;SiegeContainer(&lt;span style="color: #2b91af;"&gt;IServiceLocatorAdapter &lt;/span&gt;serviceLocator) : &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;(serviceLocator, &lt;span style="color: #0000ff;"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;GlobalContextStore&lt;/span&gt;())&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre style="margin: 0em; background-color: #fbfbfb; width: 100%;"&gt;&lt;span style="color: #0000ff;"&gt;public &lt;/span&gt;SiegeContainer(&lt;span style="color: #2b91af;"&gt;IServiceLocatorAdapter &lt;/span&gt;serviceLocator, &lt;span style="color: #2b91af;"&gt;IContextStore &lt;/span&gt;contextStore)&lt;br /&gt;{&lt;br /&gt;}&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;This context store is a very simple implementation that tracks context for the container irrespective of user session. By providing different implementations of IContextStore, you can change the way that SiegeContainer manages context for your application. This is designed to create extensibility for Siege.ServiceLocation; if there is behavior that you need that is not covered by an existing implementation, creating your own should be very easy. The definition of IContextStore looks like this:&lt;/p&gt;
&lt;div id="codeSnippetWrapper" style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 97.5%; cursor: text;"&gt;
&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px;"&gt;
&lt;pre style="margin: 0em; padding: 0px; overflow: visible; border-bottom-style: none; text-align: left; line-height: 12pt; border-right-style: none; background-color: white; width: 100%;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;interface&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;IContextStore&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0em; padding: 0px; overflow: visible; border-bottom-style: none; text-align: left; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; width: 100%;"&gt;{&lt;/pre&gt;
&lt;pre style="margin: 0em; padding: 0px; overflow: visible; border-bottom-style: none; text-align: left; line-height: 12pt; border-right-style: none; background-color: white; width: 100%;"&gt;    &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; Add(&lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; contextItem);&lt;/pre&gt;
&lt;pre style="margin: 0em; padding: 0px; overflow: visible; border-bottom-style: none; text-align: left; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; width: 100%;"&gt;    &lt;span style="color: #2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #0000ff;"&gt;object&lt;/span&gt;&amp;gt; Items { get; }&lt;/pre&gt;
&lt;pre style="margin: 0em; padding: 0px; overflow: visible; border-bottom-style: none; text-align: left; line-height: 12pt; border-right-style: none; background-color: white; width: 100%;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;At our company, we use a different implementation &amp;ndash; HttpSessionStore &amp;ndash; to manage context on a per-user session basis. As users log in, the relevant information about them is added to the context store for use in later resolutions. I will include this context store as part of the http integration project accompanying Part 4, when it is published.&lt;/p&gt;
&lt;h3&gt;&amp;nbsp;&lt;/h3&gt;
&lt;h3&gt;How do I add context to a context store?&lt;/h3&gt;
&lt;p&gt;This really depends on how you set up your implementation of IContextStore, or which implementation of IContextStore you are using (if you haven&amp;rsquo;t provided your own). There are a few ways of going about this. HttpSessionStore pulls items from the Session; Adding an item to the Session effectively adds it to the context. The SiegeContainer itself has a convenience method for this:&lt;/p&gt;
&lt;pre style="border: 1px solid #cecece; padding: 5px; overflow: auto; background-color: #fbfbfb; min-height: 40px; width: 97.5%;"&gt;&lt;pre style="margin: 0em; background-color: #fbfbfb; width: 100%;"&gt;&lt;span style="color: #0000ff;"&gt;public void &lt;/span&gt;AddContext(&lt;span style="color: #0000ff;"&gt;object &lt;/span&gt;contextItem)&lt;br /&gt;{&lt;br /&gt;}&lt;/pre&gt;
&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;Alternatively, you could add things directly through your context store instance itself. Simply register the implementation of IContextStore you desire with the container and then inject it directly into a class that requires context to be updated.&lt;/p&gt;
&lt;pre style="border: 1px solid #cecece; padding: 5px; overflow: auto; background-color: #fbfbfb; width: 97.5%;"&gt;locator.Register(&lt;span style="color: #2b91af;"&gt;Given&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;IContextStore&lt;/span&gt;&amp;gt;.Then&amp;lt;&lt;span style="color: #2b91af;"&gt;HttpSessionStore&lt;/span&gt;&amp;gt;());&lt;/pre&gt;
&lt;p&gt;or &lt;/p&gt;
&lt;pre style="border: 1px solid #cecece; padding: 5px; overflow: auto; background-color: #fbfbfb; width: 97.5%;"&gt;locator.Register(&lt;span style="color: #2b91af;"&gt;Given&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;IContextStore&lt;/span&gt;&amp;gt;.Then(locator.ContextStore));&lt;/pre&gt;
&lt;p&gt;Using this approach, you could monitor the status of your vendor integration in the following manner:&lt;/p&gt;
&lt;div id="codeSnippetWrapper" style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 97.5%; cursor: text;"&gt;
&lt;div id="codeSnippet" style="padding: 0px; overflow: visible; border-bottom-style: none; text-align: left; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; width: 100%;"&gt;
&lt;pre style="margin: 0em; padding: 0px; overflow: visible; border-bottom-style: none; text-align: left; line-height: 12pt; border-right-style: none; background-color: white; width: 100%;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;VendorMonitor&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; overflow: visible; border-bottom-style: none; text-align: left; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; width: 100%;"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; overflow: visible; border-bottom-style: none; text-align: left; line-height: 12pt; border-right-style: none; background-color: white; width: 100%;"&gt;    &lt;span style="color: #0000ff;"&gt;private&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;IContextStore&lt;/span&gt; contextStore;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; overflow: visible; border-bottom-style: none; text-align: left; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; width: 100%;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; overflow: visible; border-bottom-style: none; text-align: left; line-height: 12pt; border-right-style: none; background-color: white; width: 100%;"&gt;    &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; VendorMonitor(&lt;span style="color: #2b91af;"&gt;IContextStore&lt;/span&gt; contextStore)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; overflow: visible; border-bottom-style: none; text-align: left; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; width: 100%;"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; overflow: visible; border-bottom-style: none; text-align: left; line-height: 12pt; border-right-style: none; background-color: white; width: 100%;"&gt;        &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.contextStore = contextStore;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; overflow: visible; border-bottom-style: none; text-align: left; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; width: 100%;"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; overflow: visible; border-bottom-style: none; text-align: left; line-height: 12pt; border-right-style: none; background-color: white; width: 100%;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; overflow: visible; border-bottom-style: none; text-align: left; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; width: 100%;"&gt;    &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; Monitor()&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; overflow: visible; border-bottom-style: none; text-align: left; line-height: 12pt; border-right-style: none; background-color: white; width: 100%;"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; overflow: visible; border-bottom-style: none; text-align: left; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; width: 100%;"&gt;        &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt;(IsVendorDown()) contextStore.Add(&lt;span style="color: #2b91af;"&gt;VendorStatus&lt;/span&gt;.Offline);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; overflow: visible; border-bottom-style: none; text-align: left; line-height: 12pt; border-right-style: none; background-color: white; width: 100%;"&gt;    }&lt;/pre&gt;
&lt;pre style="margin: 0em; padding: 0px; overflow: visible; border-bottom-style: none; text-align: left; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; width: 100%;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When the context store is updated, SiegeContainer will start serving different interfaces based on the rules specified for the various use cases registered and the context that exists in the container. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;&lt;b&gt;Contextual Resolution&lt;/b&gt;&lt;/h3&gt;
&lt;p&gt;So how do we go about resolving types that have been contextually registered? This turns out to be very easy. No different methods are needed to be called to resolve types contextually; Simply specify a contextual condition through registration using the Given-When-Then syntax and call GetInstance&amp;lt;T&amp;gt;() on the SiegeContainer. If the condition is satisfied, the container will return the type specified by your rule. If not, it will return the default (if specified). If multiple conditions apply, it will select the first applicable one. This is currently NOT the case for functions like GetAllInstances&amp;lt;T&amp;gt;. I am considering adding a function called GetAllContextualInstances&amp;lt;T&amp;gt; to cover this scenario.&lt;/p&gt;
&lt;p&gt;The part (to me) that is cool is this - If you had, say, a controller class that was injected with IOrderFulfillmentService, and you resolved that controller, when the IOrderFulfillmentService is identified as a dependency, it is resolved contextually to the appropriate type. This means that contextual resolution applies not only at the root level of an object graph, but at every level a dependency is resolved and fulfilled by the container. If your object structure is 10 levels deep, and each level has constructor injected depenendencies, any of those dependencies that are contextually registered will be compared against the tracked context and resolved either to a default use case or a conditional use case. Siege works with the provided adapters to ensure that every dependency, as it is resolved, is fulfilled contextually if applicable; not only the type you are requesting, but also the types it relies on as dependencies, and the types that THOSE types rely on as dependencies.&lt;/p&gt;
&lt;h3&gt;&lt;b&gt;Looking Ahead&lt;/b&gt;&lt;/h3&gt;
&lt;p&gt;In my next post, I will be covering how Siege.ServiceLocation has native support for extending itself to support custom use case implementations. This post will get a little deeper into the guts of how the project works and how it interacts with adapters. I hope these posts have been helpful thus far in communicating the intent of the library, how it is used, what you as a developer can do with it and how it adheres to my philosophy of simplicity, consumability and extensibility.&lt;/p&gt;
&lt;p&gt;Until next time, Happy Coding!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=The+Siege+Project%3a+Siege.ServiceLocation%2c+Part+2+-+Contextual+Registration+and+Resolution&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2009%2f12%2f09%2fthe-siege-project-siege-servicelocation-part-2-contextual-registration-and-resolution.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2009%2f12%2f09%2fthe-siege-project-siege-servicelocation-part-2-contextual-registration-and-resolution.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=38554" width="1" height="1"&gt;</content><author><name>mbratton</name><uri>http://www.lostechies.com/members/mbratton/default.aspx</uri></author><category term="Siege" scheme="http://www.lostechies.com/blogs/marcus_bratton/archive/tags/Siege/default.aspx" /><category term="IoC" scheme="http://www.lostechies.com/blogs/marcus_bratton/archive/tags/IoC/default.aspx" /></entry><entry><title>The Siege Project: Siege.ServiceLocation Part 1 - Introduction and General Use</title><link rel="alternate" type="text/html" href="/blogs/marcus_bratton/archive/2009/12/06/the-siege-project-siege-servicelocation.aspx" /><id>/blogs/marcus_bratton/archive/2009/12/06/the-siege-project-siege-servicelocation.aspx</id><published>2009-12-07T04:08:00Z</published><updated>2009-12-07T04:08:00Z</updated><content type="html">&lt;h3&gt;&lt;b&gt;The Siege Project&lt;/b&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/06/introducing-siege.aspx"&gt;Introduction&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Siege.ServiceLocation Part 1 - Introduction and General Use &lt;/li&gt;
&lt;li&gt;&lt;a target="_blank" href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/09/the-siege-project-siege-servicelocation-part-2-contextual-registration-and-resolution.aspx"&gt;Siege.ServiceLocation Part 2 &amp;ndash; Contextual Registration and Resolution &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a target="_blank" href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/10/the-siege-project-siege-servicelocation-part-3-extending-the-container-with-custom-use-cases.aspx"&gt;Siege.ServiceLocation Part 3 &amp;ndash; Extending the container with custom use cases &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/18/the-siege-project-siege-servicelocation-part-4-integrating-siege-servicelocation-with-asp-net-mvc.aspx"&gt;Siege.ServiceLocation Part 4 &amp;ndash; Integrating Siege.ServiceLocation with ASP.NET MVC &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/18/the-siege-project-siege-servicelocation-part-5-a-guide-to-getting-started-with-siege-servicelocation.aspx"&gt;Siege.ServiceLocation Part 5 &amp;ndash; A guide to getting started with Siege.ServiceLocation&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;&lt;br /&gt;Siege.ServiceLocation&lt;/h2&gt;
&lt;p&gt;In my last post, I introduced the Siege project. While that post dealt with the goals, values and philosophies of the project, this post serves as a hands-on look at the first component to be released under the Siege umbrella. This component serves to a lesser extent as a general abstraction for service locators and dependency injection containers, providing a simple syntax for component registration. To a greater extent, this library introduces a broader type of contextual registration and allows consumers to extend the registration syntax and resolution mechanisms to account for their own custom use cases.&lt;/p&gt;
&lt;h2&gt;&lt;br /&gt;What is it not?&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;I think it's important to start off with this, because I want to set expectations clearly. This is not another IoC framework. When building this my goal was not to build yet-another-IoC from the ground up. There are plenty of projects out there that do this very well already: Castle Windsor, StructureMap, and Ninject, just to name a few. These are all good frameworks that perform their function well, and the community honestly is not in need of another one of these.&amp;nbsp;My intent with this project is to be able to leverage these existing frameworks and gain the benefit of their functionality -- to stand on the shoulders of giants.&lt;/p&gt;
&lt;h2&gt;&lt;br /&gt;So what is it?&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;The Siege.ServiceLocation component is an abstraction mechanism coupled with a way to extend the existing frameworks with additional functionality. First, this component abstracts a developer away from the need to learn another subset of frameworks, with their own styles and approaches to registration and resolution of types. Secondly, Siege.ServiceLocation introduces contextual resolution to selectively resolve types based on run-time state of an application or user session. Finally, it allows developers to extend its behavior with their own custom registration and resolution behaviors. &lt;/p&gt;
&lt;p&gt;We use this at our company to write loosely coupled frameworks that can be integrated with our various projects. Where I work, we use more than one IoC, so rather than having to rewrite a lot of registration and resolution code, we simply use a different adapter when the container is constructed.&lt;/p&gt;
&lt;p&gt;Let's look at some code.&lt;span style="font-size: x-small;"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;span style="font-size: x-small;"&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;h2&gt;SiegeContainer&lt;/h2&gt;
&lt;p&gt;At the heart of Siege.ServiceLocation is the SiegeContainer class. This serves as a wrapper class for the various adapters for the different underlying IoC providers. Setting it up to use one of the various providers is easy.&amp;nbsp;This is the constructor for the SiegeContainer:&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;&lt;/span&gt;&lt;span&gt;SiegeContainer(&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span style="color: #2b91af;"&gt;IServiceLocatorAdapter&lt;/span&gt;&lt;/span&gt;&lt;span&gt; serviceLocator)&lt;br /&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;br /&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The IServiceLocatorAdapter interface provides the mechanism by which we integrate with existing IoC frameworks. For example, to use Ninject as a provider for SiegeContainer, simply instantiate like this:&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var&amp;nbsp;&lt;/span&gt;&lt;span&gt;locator = &lt;span style="color: #0000ff;"&gt;new&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span style="color: #2b91af;"&gt;SiegeContainer&lt;/span&gt;&lt;/span&gt;&lt;span&gt;(&lt;span style="color: #0000ff;"&gt;new&amp;nbsp;&lt;/span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;NinjectAdapter&lt;/span&gt;&lt;span style="color: #000000;"&gt;&lt;span&gt;(&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If you need to use a preconfigured kernel, this is also easy to do:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;&lt;/span&gt;&lt;span&gt;kernel = &lt;span style="color: #0000ff;"&gt;new&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span style="color: #2b91af;"&gt;StandardKernel&lt;/span&gt;&lt;/span&gt;&lt;span&gt;();&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var&amp;nbsp;&lt;/span&gt;&lt;span&gt;locator = &lt;span style="color: #0000ff;"&gt;new&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span style="color: #2b91af;"&gt;SiegeContainer&lt;/span&gt;&lt;/span&gt;&lt;span&gt;(&lt;span style="color: #0000ff;"&gt;new&amp;nbsp;&lt;/span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;NinjectAdapter&lt;/span&gt;&lt;span style="color: #000000;"&gt;&lt;span&gt;(kernel&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;From here there are two methods that you can use to get started:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;IServiceLocator&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;Register&amp;lt;TService&amp;gt;(&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span style="color: #2b91af;"&gt;IUseCase&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&amp;lt;TService&amp;gt; useCase);&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;TService GetInstance&amp;lt;TService&amp;gt;();&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;Included in this assembly is a syntax to help build instances of IUseCase for the consumer. This syntax aligns with my goal of simplicity and covering the 80% of use cases that I mentioned in my previous post. I personally do not like verbose registration syntaxes, xml-based registration, or overly-fluent registrations. While I understand the goals and reasons for them, and I can see their use, I do not personally feel like the value added overcomes the inherent cost of learning and understanding the API. So, for my syntax, I followed the simple BDD formula. Given, When and Then.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Given&amp;lt;T&amp;gt;&lt;/h2&gt;
&lt;p&gt;Siege.ServiceLocation includes a helper class that is used for the purpose of building instances of IUseCase for the registration of types. Out of the box, this syntax supports both basic registration and contextual registration. While I will devote another post to the contextual resolution of items, I will cover briefly the method by which you contextually register items and what the purpose of contextual resolution is.&lt;/p&gt;
&lt;h3&gt;Basic (Default) Registration&lt;/h3&gt;
&lt;p&gt;Basic registration links types to implentations. This can happen between interfaces and classes, classes and subclasses, and a class and itself. Currently Siege has no mechanism to auto-register types, and a type must be either registered through Siege or registered through the underlying provider in order to be resolved. It looks like this:&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span style="color: #2b91af;"&gt;Given&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&amp;lt;Interface&amp;gt;.&lt;span&gt;&lt;span style="color: #2b91af;"&gt;Then&lt;/span&gt;&lt;span&gt;&lt;span&gt;&amp;lt;Type&amp;gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;and registration itself looks like this:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; locator.&lt;/span&gt;&lt;span&gt;&lt;span&gt;Register&lt;/span&gt;&lt;/span&gt;&lt;span&gt;(&lt;span style="color: #0000ff;"&gt;&lt;span style="color: #2b91af;"&gt;Given&lt;/span&gt;&lt;span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;Interface&amp;gt;.&lt;/span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;Then&lt;/span&gt;&lt;span style="color: #000000;"&gt;&lt;span&gt;&amp;lt;Type&amp;gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;Under the covers, the container coordinates with the adapter to fulfill registration of the type. It also tracks the type internally for its own orchestration of the resolution of deep object graphs.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;&lt;span&gt;&lt;span&gt;Contextual Registration&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;Contextual registration links types to implementations which are later resolved only if the specified criteria are met. The criteria for these conditional resolutions is completely arbitrary and defined by the consumer. As a developer, you can specify certain types to be returned under as simple or complex criteria as you want. Simply add context as you go to the locator and it will use that context to determine which rules have been met during resolution. SiegeContainer analyzes resolution of every dependency in an object graph no matter how deep and resolves types depending on whether or a condition has been successfully met or a default case needs to be triggered.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;The syntax for the helper, Given&amp;lt;T&amp;gt;, looks like this:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span style="color: #0000ff;"&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt; locator.&lt;/span&gt;&lt;span&gt;&lt;span&gt;Register&lt;/span&gt;&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span style="color: #0000ff;"&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span style="color: #2b91af;"&gt;&lt;span style="color: #2b91af;"&gt;Given&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;Interface&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span&gt;&lt;span style="color: #000000;"&gt;.&lt;/span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;When&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;ArbitraryContextItem&amp;gt;(contextItem == someValue&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span&gt;&lt;span style="color: #000000;"&gt;.&lt;/span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;Then&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;Type&amp;gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;));&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span style="color: #0000ff;"&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span&gt;&lt;span style="color: #000000;"&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;To give a&amp;nbsp;purely contrived, but less abstract&amp;nbsp;example, imagine you have an ordering system that integrates with a third party to fulfill requests online in real time. Sometimes this vendor is down, and you want to save the orders for later processing when this occurs.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span&gt;&lt;span style="color: #000000;"&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt; locator&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;/span&gt;&lt;span&gt;&lt;span&gt;Register&lt;/span&gt;&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span&gt;&lt;span style="color: #000000;"&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span style="color: #0000ff;"&gt;&lt;span style="color: #2b91af;"&gt;&lt;span style="color: #2b91af;"&gt;Given&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;IOrderFulfillmentService&amp;gt;.&lt;/span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;Then&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;RealtimeOrderFulfillmentService&amp;gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;/span&gt;&lt;span&gt;&lt;span&gt;Register&lt;/span&gt;&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span&gt;&lt;span style="color: #000000;"&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span style="color: #2b91af;"&gt;&lt;span style="color: #2b91af;"&gt;Given&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;IOrderFulfillmentService&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span&gt;&lt;span style="color: #000000;"&gt;.&lt;/span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;When&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;VendorStatus&amp;gt;(status == VendorStatus.Offline&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span&gt;&lt;span style="color: #000000;"&gt;.&lt;/span&gt;&lt;span&gt;&lt;span style="color: #2b91af;"&gt;Then&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;DeferredOrderFulfillmentService&amp;gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;));&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;In this case, the application would contextually know to process orders in real-time or to defer them to a later time based on the status of a 3rd party integration component. This is all handled by the container, so you don't have to build additional logic into your system for determining how to handle different states of the system; This scenario assumes that there is some component performing a health check and if it fails, it notifies the locator that the state of the application is changed so it can respond accordingly. There are many different use cases for such contextually-based resolution; because the conditions are completely arbitrary, it is up to the imagination of the developer on how to use (or abuse) this feature. I will go over, in greater depth, contextual registration and resolution in the following blog post.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;Extending the container&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;Siege.ServiceLocation is built with extensibility in mind. To that end, it has the capacity to incorporate and use custom implementations of IUseCase. While this will be covered in a seperate post, it allows a consumer to extend the container to understand how to register custom scenarios and how to resolve them.&amp;nbsp; This is meant to allow myself and other members of the community to easily provide extensions to this framework without having to constantly update the source code to deliver new functionality to users. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;Looking ahead&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;In upcoming posts, I will delve deeper into how contextual registration/resolution works, how to extend the container to incorporate custom use cases and how to integrate the framework into ASP.NET MVC. My goal is to explain how these aspects of the system work in a clear and concise manner that adheres&amp;nbsp;to the main pillars of the Siege design philosophy: Keep it easy to understand and consume. Please check this framework out and leave any feedback you have in the comments section.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;Happy coding!&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=The+Siege+Project%3a+Siege.ServiceLocation+Part+1+-+Introduction+and+General+Use&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2009%2f12%2f06%2fthe-siege-project-siege-servicelocation.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2009%2f12%2f06%2fthe-siege-project-siege-servicelocation.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=38477" width="1" height="1"&gt;</content><author><name>mbratton</name><uri>http://www.lostechies.com/members/mbratton/default.aspx</uri></author><category term="Siege" scheme="http://www.lostechies.com/blogs/marcus_bratton/archive/tags/Siege/default.aspx" /><category term="IoC" scheme="http://www.lostechies.com/blogs/marcus_bratton/archive/tags/IoC/default.aspx" /></entry><entry><title>Introducing Siege</title><link rel="alternate" type="text/html" href="/blogs/marcus_bratton/archive/2009/12/06/introducing-siege.aspx" /><id>/blogs/marcus_bratton/archive/2009/12/06/introducing-siege.aspx</id><published>2009-12-07T02:20:00Z</published><updated>2009-12-07T02:20:00Z</updated><content type="html">&lt;h3&gt;&lt;b&gt;The Siege Project&lt;/b&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Introduction &lt;/li&gt;
&lt;li&gt;&lt;a target="_blank" href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/06/the-siege-project-siege-servicelocation.aspx"&gt;Siege.ServiceLocation Part 1 - Introduction and General Use &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a target="_blank" href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/09/the-siege-project-siege-servicelocation-part-2-contextual-registration-and-resolution.aspx"&gt;Siege.ServiceLocation Part 2 &amp;ndash; Contextual Registration and Resolution &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a target="_blank" href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/12/10/the-siege-project-siege-servicelocation-part-3-extending-the-container-with-custom-use-cases.aspx"&gt;Siege.ServiceLocation Part 3 &amp;ndash; Extending the container with custom use cases &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Siege.ServiceLocation Part 4 &amp;ndash; Integrating Siege.ServiceLocation with ASP.NET MVC &lt;/li&gt;
&lt;li&gt;Siege.ServiceLocation Part 5 &amp;ndash; A guide to getting started with Siege.ServiceLocation &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;A few months ago I wrote a post about &lt;a target="_self" href="http://www.lostechies.com/blogs/marcus_bratton/archive/2009/02/26/hallmarks-of-good-system-design.aspx" title="Hallmarks of Good System Design"&gt;what I consider to be good software design practices&lt;/a&gt;. I have thought a lot about the topic of what makes a design "good" for many months as I've worked on challenging systems both in my professional life and personal life. High coupling, massive frameworks, portability and testability problems and a plethora of other issues have helped to shape and change how I view software development. During that time, I began to work on several software projects to help me reduce coupling issues, increase reuse and testability.&lt;/p&gt;
&lt;p&gt;Collectively, I call these this initiative &lt;a target="_self" href="http://github.com/MarcusTheBold/Siege" title="Siege"&gt;Siege&lt;/a&gt;. This&amp;nbsp;name is a wink-and-nudge towards some challenging frameworks I've used and the feeling that I've had at times of&amp;nbsp;being under siege from&amp;nbsp;the codebases I've had to work on.&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;What is Siege?&lt;/h2&gt;
&lt;p&gt;Siege represents my philosophy on software design as much as it represents a set of frameworks that I've been working on. At every design decision point, I've tried to build against my list of design values. I've reviewed the work constantly, making revisions and updates to hold the designs in line with those values as much as to ensure the code itself is functional. I will be writing blogs specifically about each component in the framework (there are a few, and will be released over time). This blog, as an introduction, serves to explain my design values and principles, why I hold them, and why they driven me to work on this project.&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;What are the design principles and values that Siege adheres to?&lt;/h2&gt;
&lt;p&gt;I&amp;nbsp;have a small list of values that I use as&amp;nbsp;guideposts for Siege. They are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It must be easily understood&lt;/li&gt;
&lt;li&gt;It must be easily consumed&lt;/li&gt;
&lt;li&gt;It must be easily extended&lt;/li&gt;
&lt;li&gt;It must be easy to maintain&lt;/li&gt;
&lt;li&gt;It must be easy to test&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That's it. Those are very broad goals, and very subjective. I've learned a lot by looking at and using other frameworks, such as Windsor, StructureMap, Ninject, NHibernate, Active Record, Rhino Commons&amp;nbsp;as well as more than a few&amp;nbsp;others and have come to certain conclusions about things I like about these frameworks, and things I do not. Therefore, I have developed Siege along the following convictions.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I don't like massive frameworks that over time have become monoliths. I don't like frameworks that try to solve all areas of a problem domain in one tool. I prefer frameworks that are specialized to a specific problem and address that problem. Therefore, Siege will be a component framework that will involve multiple components that work in tandem to create specific and highly-targetted solutions.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;I don't like frameworks that only work with itself, or that in the process of making it easy to work with its other individual components it makes it harder to integrate other frameworks. I don't like to have a laundry list of things I must use in order for a solution to work. Therefore, Siege will be designed to integrate with other frameworks through light-weight and well-defined interfaces. Siege does not intend to reinvent the wheel, and while there may be occassional overlap of functionality, Siege will integrate as easily as possible with other frameworks to provide functionality to a consumer.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;I don't like high levels of complexity in configuration and consumption of frameworks. Therefore, Siege will provide simple and straight-forward syntax to accomplish 80% of use cases while not preventing the fulfillment of the other 20%. In other words, Siege should be able to fulfill most of your normal needs, but in cases where you need a specialized component to integrate, Siege will not hinder your ability to integrate with those solutions.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;I don't like rubbing up against the limitations of a framework without a way to extend it to cover my needs. Therefore, Siege will be built with extensibility in mind. You should not have to modify the framework to introduce new functionality, but rather, extend what is already there. This is a long-term goal and will require diligence to accomplish.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;I do not agree with the idea of things magically working with the developer not knowing why. I don't agree with the idea of programming against a number of conventions so large that it becomes almost an exercise in learning a whole new programming language to use a tool. I do not feel that these philosophies enable a consumer to understand what is happening in their system. Therefore, Siege will not by default provide a lot of "automagical" functionality. Everything should and will be easy to trace and understand. While Siege will not behave "automagically", there will be functionality available to provide for easy of consumption while still adhering to a philosophy of "be explicit".&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;I do not like coupling directly to frameworks or building applications directly on them. Siege is designed to be as light-weight and non-intrusive as possible and provides abstraction mechanisms between itself and other frameworks as a result.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The bottom line is that Siege's design philosophy is to be extensible by the consumers, to provide a simple set of interfaces that developers can understand and use, and to conform to a problem and solution ... not force the problem or solution to fit to Siege.&lt;/p&gt;
&lt;h2&gt;"Talk is cheap... Show me the code."&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;You can access the source code to the first component I am releasing &lt;a target="_self" href="http://github.com/MarcusTheBold/Siege" title="Siege"&gt;here&lt;/a&gt;&amp;nbsp;or get the binaries &lt;a target="_self" href="http://github.com/MarcusTheBold/Siege/downloads" title="Download"&gt;here&lt;/a&gt;. My next posts will go over what it is (and isn't), how to use it and how to extend it.&amp;nbsp;As more components are released, I will put up blog posts for those as well. There are several in the pipeline, but many of them still have a few revisions to go through to ensure that I have been as diligent as possible to not only adhere to my philosophy but also to ensure that I have as high level of code coverage as I can. I practice Test-Driven Development, but it is fair to say that many times I miss cases and have to go back and cover them. Additionally, I find in review that some functionality&amp;nbsp;needs to be reworked, removed, or in some cases, new functionality needs to be added.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Happy coding!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Introducing+Siege&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2009%2f12%2f06%2fintroducing-siege.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2009%2f12%2f06%2fintroducing-siege.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=38476" width="1" height="1"&gt;</content><author><name>mbratton</name><uri>http://www.lostechies.com/members/mbratton/default.aspx</uri></author><category term="Software Design" scheme="http://www.lostechies.com/blogs/marcus_bratton/archive/tags/Software+Design/default.aspx" /><category term="Siege" scheme="http://www.lostechies.com/blogs/marcus_bratton/archive/tags/Siege/default.aspx" /></entry><entry><title>Hallmarks of Good System Design</title><link rel="alternate" type="text/html" href="/blogs/marcus_bratton/archive/2009/02/26/hallmarks-of-good-system-design.aspx" /><id>/blogs/marcus_bratton/archive/2009/02/26/hallmarks-of-good-system-design.aspx</id><published>2009-02-26T05:14:00Z</published><updated>2009-02-26T05:14:00Z</updated><content type="html">&lt;p&gt;I&amp;#39;ve had a few conversations over the last week or two with some co-workers and friends about what constitutes &amp;#39;good system design&amp;#39;. I thought I&amp;#39;d post up my ideas with some short descriptions and get feedback from others. Here&amp;#39;s my list:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;1. The system is easily understood by developers of all skill levels.&lt;/p&gt;
&lt;p&gt;I really think this is imperative. If people look at how your system is put together, look at how it functions and understand it without a lot of explanation about how it works technically, you&amp;#39;ve got a good design (explaining business domain is different). If people look at your system and are immediately lost on how it all ties together, then chances are you&amp;#39;ve either over-complicated it, written something only you can maintain, or written something that people are going to have to be trained on in order to make meaningful contributions.&lt;/p&gt;
&lt;p&gt;There are usually more mid level and junior level people on most teams than senior levels and architects. If you have a system that can only really be maintained by senior level developers (and higher), then there&amp;#39;s a problem. Unfortunately, many people look at these sorts of systems and the developers that write them and assume they are very intelligent/talented/gifted/what have you. It&amp;#39;s not much different than people who converse with someone that uses a lot of &amp;quot;big words&amp;quot; (or in this industry, buzz words) that they can&amp;#39;t understand -- they think they must be intelligent.&lt;/p&gt;
&lt;p&gt;Being hard to understand isn&amp;#39;t a sign of intelligence or good design. An intelligent person is someone that can explain concepts and ideas to people that don&amp;#39;t know anything about a subject matter so that they can easily understand it. In the same way, an intelligently designed system is one that can be easily understood by developers that didn&amp;#39;t design and build it.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;2. Refactoring is not an exercise in total redesign&lt;/p&gt;
&lt;p&gt;A well designed system is one that accomplishes exactly what the business needs today but is put together in a way that can easily be modified to support the business needs of tomorrow. Part of this is making your system loosely coupled, part of it is understanding concepts like abstraction, encapsulation and dependency inversion work. If you need to switch from your own home-grown subsystem to a 3rd party service, you should be able to create new classes and implement the interfaces defined in your system.&lt;/p&gt;
&lt;p&gt;You should not have to tear apart how the entire system works.&lt;/p&gt;
&lt;p&gt;Forethought must be reasonable; it is too easy to conceive an overwhelming set of situations that you may have to contend with. YAGNI is a key principle here. Use wisdom; design for today with the ability to easily refactor support for tomorrow, but don&amp;#39;t go overboard.&lt;/p&gt;
&lt;p&gt;3. Functionality is easily consumed&lt;/p&gt;
&lt;p&gt;A well-designed system is one that is written with the consumer in mind; Functionality and intent should be easily understood by the person consuming it without having to dig through the implementation to make sure that it actually does what is expected. I shouldn&amp;#39;t need some secret tribal knowledge to know what your component does; it should tell me what it does and it should do what it says. &amp;quot;No-ops&amp;quot; do not adhere to this philosophy. If your class has a function on it, that function should do what it claims to do. As a consumer, I shouldn&amp;#39;t have to know whether or not a function I need to call will actually perform the operation that it advertises.&lt;/p&gt;
&lt;p&gt;Functionality should be designed with ease-of-use in mind. I should be able to instantiate your object and give it whatever dependencies it requires in order to function and then execute whatever methods I need to execute in order to accomplish the objective at hand. I should not need any secret tribal knowledge on the side effects of what I pass in to these functions. If your class requires a dependency and I pass it null, don&amp;#39;t treat it as a secret directive to start instantiating and using some predefined implementation. That is not intuitive and will not produce the results that I would expect.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;4. Functionality is easily maintained&lt;/p&gt;
&lt;p&gt;A well-designed system is one that can be maintained by anyone. Intent should be clear and easy to understand and the internals of your component should be self-descriptive along the lines of functionality provided. Methods should do one thing and one thing only. If you&amp;#39;ve written something that no one else feels comfortable trying to enhance, you&amp;#39;ve got a bad design. If your design does not make sense to other people, you have a bad design. One of the most important things about design is that it must be maintainable -- and for it to be maintainable, other people have to feel comfortable with it and be able to understand it. &lt;/p&gt;
&lt;p&gt;Complex problems are usually a bunch of smaller, simple problems. Build solutions that are built from smaller, simple solutions.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;5. Tools and frameworks should be included because the benefits outweigh the costs&lt;/p&gt;
&lt;p&gt;There are a lot of tools and frameworks that do a lot of different things. Each of them come with a set of benefits and a set of costs. Take a great care when you choose them -- each one comes with a learning curve and will require time for developers unfamiliar with the tool to become productive with it. The more tools you throw into something, the more time it will take. Pick the tools that make the most sense for the problem you are trying to solve.&lt;/p&gt;
&lt;p&gt;Including a tool or a framework simply because it seems &amp;#39;cool&amp;#39; is not a valid reason. Doing it because you want to learn something new is not either. And if you need a tool or framework, be intelligent about how you introduce it as a dependency into your system. In most cases, you do not need a reference to it in every assembly. One would suffice, if you encapsulate it and interact with it through your own interfaces.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Those are a handful of things that I consider necessary for good system design. There are a lot of others, and in any design, there will always be a balancing act between many of these ideas and reality. I&amp;#39;d like to hear what other people think contributes to good system design.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Hallmarks+of+Good+System+Design&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2009%2f02%2f26%2fhallmarks-of-good-system-design.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2009%2f02%2f26%2fhallmarks-of-good-system-design.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=19100" width="1" height="1"&gt;</content><author><name>mbratton</name><uri>http://www.lostechies.com/members/mbratton/default.aspx</uri></author></entry><entry><title>Going down the IoC rabbit hole</title><link rel="alternate" type="text/html" href="/blogs/marcus_bratton/archive/2008/10/28/going-down-the-ioc-rabbit-hole.aspx" /><id>/blogs/marcus_bratton/archive/2008/10/28/going-down-the-ioc-rabbit-hole.aspx</id><published>2008-10-28T04:45:00Z</published><updated>2008-10-28T04:45:00Z</updated><content type="html">&lt;p&gt;I&amp;#39;ve started a new position and one of the first projects I&amp;#39;m going to be working on relies on Windsor to do it&amp;#39;s dependency management. Having only had a small amount of exposure before, I&amp;#39;m looking forward to the opportunity to learn more about&amp;nbsp;the technology and the principles behind it in a&amp;nbsp;practical application. For anyone with experience out there, what are the benefits and the pitfalls&amp;nbsp;associated with using this?&lt;/p&gt;
&lt;p&gt;I have a list of concerns of my own but I&amp;#39;m trying to keep an open&amp;nbsp;mind because of my limited exposure. I&amp;#39;d certainly love to hear what other people think about using it and what their experiences have been like.&amp;nbsp;I&amp;#39;ll follow up with my own experiences after a few weeks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Going+down+the+IoC+rabbit+hole&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2008%2f10%2f28%2fgoing-down-the-ioc-rabbit-hole.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2008%2f10%2f28%2fgoing-down-the-ioc-rabbit-hole.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=5685" width="1" height="1"&gt;</content><author><name>mbratton</name><uri>http://www.lostechies.com/members/mbratton/default.aspx</uri></author></entry><entry><title>Those pesky indexers!</title><link rel="alternate" type="text/html" href="/blogs/marcus_bratton/archive/2008/10/02/those-pesky-indexers.aspx" /><id>/blogs/marcus_bratton/archive/2008/10/02/those-pesky-indexers.aspx</id><published>2008-10-02T19:29:00Z</published><updated>2008-10-02T19:29:00Z</updated><content type="html">&lt;p&gt;Those pesky string indexers.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve worked on projects in the past where Microsoft has given developers more than enough rope to hang themselves, the rest of the team and any chance at easily maintaining the application. One common piece of rope is when they give developers a generic dictionary object to cram information into. ViewState, SessionState and recently in ASP.NET MVC, ViewData.&lt;/p&gt;
&lt;p&gt;Giving developers these bucket-like objects is simply inviting people to make stuff up as they go. They get used as catch-alls, with people making up their own key-names ad hoc and rarely checking to see if someone else has used it. I&amp;#39;ve worked on several applications before where multiple developers decide to store the same value in something like SessionState with key names that are slightly different (userID vs userId, for example). This makes things hard to maintain as bugs creep up in a system and developers struggle to track them down. In the end, it is the fault of lazy or inobservant developers for doing it, but I lay some of the blame at a framework that makes it all too easy to do.&lt;/p&gt;
&lt;p&gt;If things were strongly typed, it&amp;#39;d be easier. You&amp;#39;d be able to track code issues by examining uses of your interface. New &amp;quot;keys&amp;quot; would be introduced as properties to your interface, informing consumers as to what properties are already in use in the system, promoting better self-documentation. The tendancy of developers to use these objects as a catch-all for whatever piece of information they find convenient to cram inside would drop dramatically; It&amp;#39;s harder to justify extending an interface for something that will be used once in an application than it is just to tuck it into one of these objects.&lt;/p&gt;
&lt;p&gt;What I&amp;#39;m suggesting here isn&amp;#39;t revolutionary at all but I&amp;#39;m constantly surprised at the number of shops that let this sort of behaviour go on. &lt;/p&gt;
&lt;p&gt;Recently, I&amp;#39;ve been working a lot with the ASP.NET MVC framework. I love it, it&amp;#39;s a very cool tool. But again you have a chance here to hang yourself if you&amp;#39;re not careful by interaction with the form values and the viewdatadictionary. This has come up a handful of times with the team I&amp;#39;m working with, where typos have caused bugs to creep up, or people aren&amp;#39;t aware of what information is being put into the viewdatadictionary simply because it&amp;#39;s not very self-documenting.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s an example of how I&amp;#39;m handling this. It could be better, but it works for now.&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;ViewResult&lt;/font&gt;&lt;font size="2"&gt; AddUser()&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#2b91af"&gt;I&lt;/font&gt;&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;AddUserView&lt;/font&gt;&lt;font size="2"&gt; view = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;AddUserView&lt;/font&gt;&lt;font size="2"&gt;(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;.ViewData, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;.FormData);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;var&lt;/font&gt;&lt;font size="2"&gt; model = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;UserModel&lt;/font&gt;&lt;font size="2"&gt;(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;.UserRepository&lt;/font&gt;&lt;font size="2"&gt;);&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; User&lt;/font&gt;&lt;font size="2"&gt; user = model.CreateUser(view.UserName);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user.IsAuthorized = view.IsAuthorized;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user.Email = view.EmailAddress;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user.FirstName = view.FirstName;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user.LastName = view.LastName;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;model.Save(user);&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/font&gt;&lt;font size="2"&gt; View(&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;UserList&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;font color="#0000ff" size="2"&gt;&lt;/p&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;AddUserView&lt;/font&gt;&lt;font size="2"&gt; : &lt;font color="#2b91af"&gt;ViewWrapper,&amp;nbsp;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#2b91af"&gt;IAddUserView&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; AddUserView(&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;ViewDataDictionary&lt;/font&gt;&lt;font size="2"&gt; viewData, &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;NameValueCollection&lt;/font&gt;&lt;font size="2"&gt; formData) : &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;base&lt;/font&gt;&lt;font size="2"&gt;(&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;AddUser&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;, viewData, formData) { }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; UserName&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;get&lt;/font&gt;&lt;font size="2"&gt; { &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;font size="2"&gt; GetData(&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;UserName&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;); }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;set&lt;/font&gt;&lt;font size="2"&gt; { &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;.ViewData[&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;UserName&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;] = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;value&lt;/font&gt;&lt;font size="2"&gt;; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; FirstName&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;get&lt;/font&gt;&lt;font size="2"&gt; { &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;font size="2"&gt; GetData(&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;FirstName&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;); }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;set&lt;/font&gt;&lt;font size="2"&gt; { &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;.ViewData[&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;FirstName&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;] = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;value&lt;/font&gt;&lt;font size="2"&gt;; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; LastName&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;get&lt;/font&gt;&lt;font size="2"&gt; { &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;font size="2"&gt; GetData(&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;LastName&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;); }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;set&lt;/font&gt;&lt;font size="2"&gt; { &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;.ViewData[&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;LastName&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;] = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;value&lt;/font&gt;&lt;font size="2"&gt;; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; EmailAddress&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;get&lt;/font&gt;&lt;font size="2"&gt; { &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;font size="2"&gt; GetData(&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;EmailAddress&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;); }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;set&lt;/font&gt;&lt;font size="2"&gt; { &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;.ViewData[&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;EmailAddress&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;] = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;value&lt;/font&gt;&lt;font size="2"&gt;; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;bool&lt;/font&gt;&lt;font size="2"&gt; IsAuthorized&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;get&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;bool&lt;/font&gt;&lt;font size="2"&gt;? data = GetData&amp;lt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt;, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;bool&lt;/font&gt;&lt;font size="2"&gt;?&amp;gt;(&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;IsAuthorized&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;, formValue =&amp;gt; formValue == &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;on&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;, viewValue =&amp;gt; viewValue ?? &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;false&lt;/font&gt;&lt;font size="2"&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;font size="2"&gt; (&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;bool&lt;/font&gt;&lt;font size="2"&gt;)data;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;set&lt;/font&gt;&lt;font size="2"&gt; { &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;.viewData[&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;IsAuthorized&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;] = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;value&lt;/font&gt;&lt;font size="2"&gt;; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/p&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;ViewWrapper&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;readonly&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; viewName;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;protected&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;readonly&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;ViewDataDictionary&lt;/font&gt;&lt;font size="2"&gt; viewData;&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;private&lt;/font&gt; &lt;font color="#0000ff"&gt;readonly&lt;/font&gt; &lt;font color="#2b91af"&gt;FormDataIndexer&lt;/font&gt; formData;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/font&gt; ViewWrapper(&lt;font color="#0000ff"&gt;string&lt;/font&gt; viewName, &lt;font color="#2b91af"&gt;ViewDataDictionary&lt;/font&gt; viewData, &lt;font color="#2b91af"&gt;NameValueCollection&lt;/font&gt; formData)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;this&lt;/font&gt;.viewName = viewName;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;this&lt;/font&gt;.viewData = viewData;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;this&lt;/font&gt;.formData = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;FormDataIndexer&lt;/font&gt;(formData);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&lt;/font&gt; &lt;font color="#0000ff"&gt;static&lt;/font&gt; &lt;font color="#0000ff"&gt;implicit&lt;/font&gt; &lt;font color="#0000ff"&gt;operator&lt;/font&gt; &lt;font color="#2b91af"&gt;ViewResult&lt;/font&gt;(&lt;font color="#2b91af"&gt;ViewWrapper&lt;/font&gt; wrapper)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#2b91af"&gt;ViewResult&lt;/font&gt; result = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;ViewResult&lt;/font&gt;();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;result.ViewName = wrapper.ViewName;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;result.ViewData = wrapper.ViewData;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;return&lt;/font&gt; result;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/font&gt; &lt;font color="#0000ff"&gt;string&lt;/font&gt; ViewName&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;get&lt;/font&gt; { &lt;font color="#0000ff"&gt;return&lt;/font&gt; viewName; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/font&gt; &lt;font color="#2b91af"&gt;ViewDataDictionary&lt;/font&gt; ViewData&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;get&lt;/font&gt; { &lt;font color="#0000ff"&gt;return&lt;/font&gt; viewData; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected&lt;/font&gt; &lt;font color="#0000ff"&gt;string&lt;/font&gt; GetData(&lt;font color="#0000ff"&gt;string&lt;/font&gt; key)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;return&lt;/font&gt; GetData&amp;lt;&lt;font color="#0000ff"&gt;object&lt;/font&gt;, &lt;font color="#0000ff"&gt;string&lt;/font&gt;&amp;gt;(key, formValue =&amp;gt; formValue == &lt;font color="#0000ff"&gt;null&lt;/font&gt; ? &lt;font color="#a31515"&gt;&amp;quot;&amp;quot;&lt;/font&gt; : formValue.ToString(), viewValue =&amp;gt; viewValue);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected&lt;/font&gt; TResult GetData&amp;lt;TInput, TResult&amp;gt;(&lt;font color="#0000ff"&gt;string&lt;/font&gt; key, &lt;font color="#2b91af"&gt;Func&lt;/font&gt;&amp;lt;TInput, TResult&amp;gt; formEvaluation)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;if&lt;/font&gt; (formData.ContainsKey(key)) &lt;font color="#0000ff"&gt;return&lt;/font&gt; formEvaluation.Invoke((TInput)formData[key]);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;return&lt;/font&gt; (TResult)viewData[key];&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font size="2"&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected&lt;/font&gt; TResult GetData&amp;lt;TInput, TResult&amp;gt;(&lt;font color="#0000ff"&gt;string&lt;/font&gt; key, &lt;font color="#2b91af"&gt;Func&lt;/font&gt;&amp;lt;TInput, TResult&amp;gt; formEvaluation, &lt;font color="#2b91af"&gt;Func&lt;/font&gt;&amp;lt;TResult, TResult&amp;gt; viewEvaluation)&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;if&lt;/font&gt; (formData.ContainsKey(key)) &lt;font color="#0000ff"&gt;return&lt;/font&gt; formEvaluation.Invoke((TInput)formData[key]);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;return&lt;/font&gt; viewEvaluation.Invoke((TResult)viewData[key]);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;}&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;internal&lt;/font&gt; &lt;font color="#0000ff"&gt;interface&lt;/font&gt; &lt;font color="#2b91af"&gt;IIndexer&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;object&lt;/font&gt; &lt;font color="#0000ff"&gt;this&lt;/font&gt;[&lt;font color="#0000ff"&gt;string&lt;/font&gt; index] { &lt;font color="#0000ff"&gt;get&lt;/font&gt;; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;bool&lt;/font&gt; ContainsKey(&lt;font color="#0000ff"&gt;string&lt;/font&gt; key);&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;internal&lt;/font&gt; &lt;font color="#0000ff"&gt;class&lt;/font&gt; &lt;font color="#2b91af"&gt;FormDataIndexer&lt;/font&gt; : &lt;font color="#2b91af"&gt;IIndexer&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;private&lt;/font&gt; &lt;font color="#0000ff"&gt;readonly&lt;/font&gt; &lt;font color="#2b91af"&gt;NameValueCollection&lt;/font&gt; formData;&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt; FormDataIndexer(&lt;font color="#2b91af"&gt;NameValueCollection&lt;/font&gt; formData)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;this&lt;/font&gt;.formData = formData;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font size="2"&gt;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;object&lt;/font&gt; &lt;font color="#0000ff"&gt;this&lt;/font&gt;[&lt;font color="#0000ff"&gt;string&lt;/font&gt; index]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;get&lt;/font&gt; { &lt;font color="#0000ff"&gt;return&lt;/font&gt; &lt;font color="#0000ff"&gt;this&lt;/font&gt;.formData[index]; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;bool&lt;/font&gt; ContainsKey(&lt;font color="#0000ff"&gt;string&lt;/font&gt; key)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;foreach&lt;/font&gt;(&lt;font color="#0000ff"&gt;string&lt;/font&gt; collectionKey &lt;font color="#0000ff"&gt;in&lt;/font&gt; &lt;font color="#0000ff"&gt;this&lt;/font&gt;.formData.AllKeys)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;if&lt;/font&gt; (collectionKey == key) &lt;font color="#0000ff"&gt;return&lt;/font&gt; &lt;font color="#0000ff"&gt;true&lt;/font&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;return&lt;/font&gt; &lt;font color="#0000ff"&gt;false&lt;/font&gt;;&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;This example may be a little over the top, but I really do wish development shops would see more value in coding against interfaces instead of writing hard-to-maintain code against bucket objects like the above, or things like SessionState or ViewState. It doesn&amp;#39;t take much effort to make a SessionWrapper and expose things as properties, and it would make life a lot easier for people trying to track down bugs.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;Of course, just because you build it doesn&amp;#39;t mean they can&amp;#39;t ignore it and use the buckets anyway... but if that happens, then it&amp;#39;s a different problem all together.&lt;/font&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Those+pesky+indexers!&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2008%2f10%2f02%2fthose-pesky-indexers.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2008%2f10%2f02%2fthose-pesky-indexers.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=5239" width="1" height="1"&gt;</content><author><name>mbratton</name><uri>http://www.lostechies.com/members/mbratton/default.aspx</uri></author></entry><entry><title>Procedural LOLCoding</title><link rel="alternate" type="text/html" href="/blogs/marcus_bratton/archive/2007/10/28/procedural-lolcoding.aspx" /><id>/blogs/marcus_bratton/archive/2007/10/28/procedural-lolcoding.aspx</id><published>2007-10-28T22:39:00Z</published><updated>2007-10-28T22:39:00Z</updated><content type="html">&lt;font face="Times New Roman" size="3"&gt;Recently I had the great pleasure to be introduced to &lt;/font&gt;&lt;a title="LOLCode" href="http://lolcode.com/"&gt;&lt;font face="Times New Roman" size="3"&gt;LOLCode&lt;/font&gt;&lt;/a&gt;&lt;font face="Times New Roman" size="3"&gt;. It&amp;#39;s an idiomatic syntax based on a series of images found at &lt;/font&gt;&lt;a class="" href="http://www.lolcat.com/"&gt;&lt;font face="Times New Roman" color="#0000ff" size="3"&gt;LOLCat&lt;/font&gt;&lt;/a&gt;&lt;font face="Times New Roman" size="3"&gt; and &lt;/font&gt;&lt;a href="http://icanhascheezburger.com/"&gt;&lt;font face="Times New Roman" size="3"&gt;ICanHasCheezeBurger&lt;/font&gt;&lt;/a&gt;&lt;font face="Times New Roman" size="3"&gt;. In any event, currently LOLCode syntax is at specification 1.2. There are several compilers including a &lt;/font&gt;&lt;a href="http://code.google.com/p/lolcode-dot-net/"&gt;&lt;font face="Times New Roman" size="3"&gt;LOLCode.NET&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt;&lt;font face="Times New Roman"&gt; compiler. I gave it a try, but as of the time of this posting, it didn&amp;#39;t seem to be able to handle if statements too well.&lt;/font&gt;&lt;/font&gt;&lt;font size="3"&gt;&lt;font face="Times New Roman"&gt;Currently in specification 1.2, everything is still procedural, though there are proposals for OOP LOLCode in the proposed 1.3 specification. I thought for fun I&amp;#39;d post up some LOLCode snippets from a tic tac toe program I wrote in LOLCode to see if I could get it to work.&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="3"&gt;&lt;font face="Times New Roman"&gt;&lt;/font&gt;&lt;/font&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;HOW DUZ I&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt; CheckForWinningMatch &lt;span style="COLOR:blue;"&gt;YR&lt;/span&gt; index1 &lt;span style="COLOR:blue;"&gt;AN YR&lt;/span&gt; index2 &lt;span style="COLOR:blue;"&gt;AN YR&lt;/span&gt; index3 &lt;span style="COLOR:blue;"&gt;AN YR&lt;/span&gt; array&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style="COLOR:blue;"&gt;BOTH SAEM&lt;/span&gt; array!!index1 &lt;span style="COLOR:blue;"&gt;AN&lt;/span&gt; array!!index2, &lt;span style="COLOR:blue;"&gt;O RLY?&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style="COLOR:blue;"&gt;YA RLY&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style="COLOR:blue;"&gt;BOTH SAEM&lt;/span&gt; array!!index1 &lt;span style="COLOR:blue;"&gt;AN&lt;/span&gt; array!!index3, &lt;span style="COLOR:blue;"&gt;O RLY?&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style="COLOR:blue;"&gt;YA RLY&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style="COLOR:blue;"&gt;BOTH SAEM&lt;/span&gt; array!!index1 &lt;span style="COLOR:blue;"&gt;AN &lt;/span&gt;&lt;span style="COLOR:#cc3300;"&gt;&amp;quot;X&amp;quot;&lt;/span&gt;, &lt;span style="COLOR:blue;"&gt;O RLY?&lt;/span&gt;&lt;br /&gt;&lt;span style="COLOR:blue;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;YA RLY&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FOUND YR WIN&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style="COLOR:blue;"&gt;MEBBE BOTH SAEM&lt;/span&gt; array!!index1 &lt;span style="COLOR:blue;"&gt;AN &lt;/span&gt;&lt;span style="COLOR:#cc3300;"&gt;&amp;quot;O&amp;quot;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style="COLOR:blue;"&gt;FOUND YR WIN&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;OIC&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;OIC&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;OIC&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style="COLOR:blue;"&gt;FOUND YR FAIL&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IF U SAY SO&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="COLOR:blue;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="COLOR:blue;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;The above code snippet checks a one dimensional array (I don&amp;#39;t think it supports multidimensional arrays yet, though I could be wrong) for combinations of the letters X and O for any sort of winning combination. Some of LOLCode syntax includes:&lt;/span&gt; 
&lt;ul&gt;
&lt;li&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Functions declarations in LOLCode start with &amp;quot;HOW DUZ I&amp;quot; and end with &amp;quot;IF YOU SAY SO&amp;quot;.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;IF statements are equivilent to &amp;quot;O RLY?&amp;quot; and and equivilency is expressed as &amp;quot;BOTH SAEM&amp;quot;. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;quot;YA RLY&amp;quot; indicates a positive match, and &amp;quot;NO WAI&amp;quot; indicates a negative match on the condition.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;quot;MEBBE&amp;quot; corresponds to &amp;quot;else if&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;If statements are closed with &amp;quot;OIC&amp;quot; (oh, I see) &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Return statements are expressed as either &amp;quot;FOUND YR&amp;quot;, followed by a value, or as &amp;quot;GTFO&amp;quot; which returns a void&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;The !! operator acts as an indexer, though my understanding is that in OOP LOLCode it may be used to access properties and methods as well&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;The TROOF data type (boolean), is expressed as either WIN (true) and FAIL (false)\&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Other data types include BUKKIT (array), NOOB (null), NUMBAR (float), NUMBR (int), YARN (string)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;The SMOOSH keyword handles string concatenation&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Programs start with HAI and end with KTHXBYE&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Here is my &amp;quot;main&amp;quot; method&amp;#39;s code.&lt;/span&gt;&lt;/p&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;HAI&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;I HAS A&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt; array &lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;ITZ A BUKKIT&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;I HAS A&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt; char &lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;ITZ&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:#cc3300;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;quot;X&amp;quot;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DrawTicTacToe array&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IM IN YR LOOP&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;BOTH SAEM&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt; GetWinningCombination array &lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;AN WIN&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;, &lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;O RLY?&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;YA RLY&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;VISIBLE SMOOSH&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt; char &lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:#cc3300;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;quot; is winnar!!&amp;quot;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;GTFO&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;OIC&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GetUserInput char array&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DrawTicTacToe array&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;BOTH SAEM&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt; char &lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;AN&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:#cc3300;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;quot;X&amp;quot;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;, &lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;O RLY?&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;YA RLY&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;char &lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;R&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:#cc3300;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;quot;O&amp;quot;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;NO WAI&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;char&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt; R&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:#cc3300;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;quot;X&amp;quot;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OIC&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IM OUTTA YR LOOP&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;KTHXBYE&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;I grabbed a java compiler from the LOLCode website that appears to have support for the proposed 1.3 specs.&lt;/span&gt; 
&lt;p&gt;&lt;span style="FONT-SIZE:9.5pt;COLOR:black;FONT-FAMILY:&amp;#39;Arial&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;OOP LOLCode, here I come!&lt;/span&gt;&lt;/p&gt;&lt;font face="Calibri" size="3"&gt;&amp;nbsp;&lt;/font&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Procedural+LOLCoding&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2007%2f10%2f28%2fprocedural-lolcoding.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2007%2f10%2f28%2fprocedural-lolcoding.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=1185" width="1" height="1"&gt;</content><author><name>mbratton</name><uri>http://www.lostechies.com/members/mbratton/default.aspx</uri></author></entry><entry><title>Aspect-oriented approaches to software development</title><link rel="alternate" type="text/html" href="/blogs/marcus_bratton/archive/2007/10/25/aspect-oriented-approaches-to-software-development.aspx" /><id>/blogs/marcus_bratton/archive/2007/10/25/aspect-oriented-approaches-to-software-development.aspx</id><published>2007-10-25T14:39:00Z</published><updated>2007-10-25T14:39:00Z</updated><content type="html">&lt;p&gt;A while back, I wrote &lt;a class="" title="a little post" href="http://www.lostechies.com/blogs/marcus_bratton/archive/2007/08/02/what-does-that-function-do-really.aspx" target="_blank"&gt;a little post&lt;/a&gt; alluding to ways to reuse certain processes that are duplicated in code throughout any given system (event logging, in my example). In this post, I&amp;#39;d like to show you how I implemented a possible solution using aspect oriented programming.&lt;/p&gt;
&lt;p style="FONT-SIZE:24px;"&gt;What is Aspect Oriented Programming?&lt;/p&gt;
&lt;p&gt;Basically, the idea that there are types of processes that occur in multiple places in a system, commonly referred to as &amp;quot;cross-cutting concerns&amp;quot;. Aspects are implementations of these concerns, written so that they can be reused in a system. In the logging example, the need to log exceptions is a concern, and the aspect is a piece of code that fulfills this need. The idea behind aspect oriented programming is to identify these cross-cutting concerns, create aspects to manage them, and introduce their behaviors into the points of a system that their behavior needs to govern. In my example, I will accomplish this by creating some custom&amp;nbsp;attributes and aspects&amp;nbsp;as well as&amp;nbsp;decorating classes and methods. As these objects are instantiated and their methods are invoked, I will be intercepting messages and injecting the behavior defined by my aspect. &lt;/p&gt;
&lt;p style="FONT-SIZE:24px;"&gt;A Consumer&amp;#39;s View&lt;/p&gt;
&lt;p style="FONT-SIZE:24px;"&gt;&lt;font size="2"&gt;Here is my simplistic implementation:&amp;nbsp;&lt;/font&gt;&lt;/p&gt;
&lt;p style="FONT-SIZE:24px;"&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;HelloWorld&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;{&lt;/font&gt;&lt;font size="2"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt; SendGreeting()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;Messenger&lt;/font&gt;&lt;font size="2"&gt; messenger = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;Messenger&lt;/font&gt;&lt;font size="2"&gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; messenger.SendMessage(&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;Hello World!&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p style="FONT-SIZE:24px;"&gt;&lt;font size="2"&gt;Running this code produces the following &amp;quot;logged&amp;quot; output:&lt;/font&gt;&lt;/p&gt;
&lt;p style="FONT-SIZE:24px;"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="FONT-SIZE:24px;"&gt;&lt;font size="2"&gt;Attempting connection...&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;Logging Exception: A problem occurred!&lt;/font&gt;&lt;/p&gt;
&lt;p style="FONT-SIZE:24px;"&gt;&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="FONT-SIZE:24px;"&gt;&lt;font size="2"&gt;All right, so how does this work? Here&amp;#39;s my messenger class.&lt;/font&gt;&lt;/p&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;
&lt;p&gt;[&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;Loggable&lt;/font&gt;&lt;font size="2"&gt;]&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;Messenger&lt;/font&gt;&lt;font size="2"&gt; : &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;ContextBoundObject&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;LogException&lt;/font&gt;&lt;font size="2"&gt;]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt; SendMessage(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; message)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;Console&lt;/font&gt;&lt;font size="2"&gt;.WriteLine(&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;Attempting Connection...&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;throw&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;Exception&lt;/font&gt;&lt;font size="2"&gt;(&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;A problem occurred!&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;First thing you might notice is that it inherits from a class called ContextBoundObject. By inheriting from this class, we will recieve the context needed from the runtime&amp;nbsp;and intercept messages in order to extend the invocation of SendMessage to include the behavior defined by our aspect. Also, there are two different types of attributes being used here... [Loggable] and [LogException].&lt;/p&gt;
&lt;p style="FONT-SIZE:24px;"&gt;[Loggable]&lt;/p&gt;
&lt;p&gt;The [Loggable] attribute is a context attribute used to associate our Aspect into the message chain. Below is the source code.&lt;/p&gt;&lt;font size="2"&gt;
&lt;p&gt;[&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;AttributeUsage&lt;/font&gt;&lt;font size="2"&gt;(&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;AttributeTargets&lt;/font&gt;&lt;font size="2"&gt;.Class)]&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;LoggableAttribute&lt;/font&gt;&lt;font size="2"&gt; : &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;ContextAttribute&lt;/font&gt;&lt;font size="2"&gt;, &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;IContributeObjectSink&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; LoggableAttribute() : &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;base&lt;/font&gt;&lt;font size="2"&gt;(&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;Loggable&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;) { }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;override&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt; GetPropertiesForNewContext(&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;IConstructionCallMessage&lt;/font&gt;&lt;font size="2"&gt; msg)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; msg.ContextProperties.Add(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;IMessageSink&lt;/font&gt;&lt;font size="2"&gt; GetObjectSink(&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;MarshalByRefObject&lt;/font&gt;&lt;font size="2"&gt; obj, &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;IMessageSink&lt;/font&gt;&lt;font size="2"&gt; nextSink)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;LogExceptionAspect&lt;/font&gt;&lt;font size="2"&gt;(nextSink);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;The implementation here is fairly straight-forward. The attribute can only be used with classes and when it is instantiated, it will add itself to the message&amp;#39;s context and add our aspect to the message chain for execution. Also, when instantiating LogExceptionAspect, we give it a reference to the next message sink in the chain, allowing us to insert our aspect as a link in the chain.&lt;/p&gt;
&lt;p style="FONT-SIZE:24px;"&gt;[LogException]&lt;/p&gt;
&lt;p&gt;The [LogException] attribute is a simple attribute that houses our logging code, and can only be used on methods.&lt;/p&gt;&lt;font size="2"&gt;[&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;AttributeUsage&lt;/font&gt;&lt;font size="2"&gt;(&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;AttributeTargets&lt;/font&gt;&lt;font size="2"&gt;.Method&lt;/font&gt;&lt;font size="2"&gt;)]&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;LogExceptionAttribute&lt;/font&gt;&lt;font size="2"&gt; : &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;Attribute&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt; Process(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; message)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;EventLogger&lt;/font&gt;&lt;font size="2"&gt;().LogMessage(message);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p style="FONT-SIZE:24px;"&gt;LogExceptionAspect&lt;/p&gt;
&lt;p&gt;The LogExceptionAspect class, which is part of the [Loggable] context attribute&amp;#39;s implementation, is a message sink. When the chain of message sinks is being processed, the runtime will get a reference to this class and invoke IMessage&lt;font size="2"&gt;.SyncProcessMessage. This function will house code related to our logging process.&lt;/font&gt;&lt;/p&gt;&lt;font size="2"&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;LogExceptionAspect&lt;/font&gt;&lt;font size="2"&gt; : &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;IMessageSink&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;private&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;readonly&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;IMessageSink&lt;/font&gt;&lt;font size="2"&gt; nextMessageSink;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;IMessageSink&lt;/font&gt;&lt;font size="2"&gt; NextSink&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;get&lt;/font&gt;&lt;font size="2"&gt; { &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;.nextMessageSink; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/font&gt;&lt;font size="2"&gt; LogExceptionAspect(&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;IMessageSink&lt;/font&gt;&lt;font size="2"&gt; nextMessageSink)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;.nextMessageSink = nextMessageSink;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;IMessage&lt;/font&gt;&lt;font size="2"&gt; SyncProcessMessage(&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;IMessage&lt;/font&gt;&lt;font size="2"&gt; msg)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;MethodBase&lt;/font&gt;&lt;font size="2"&gt; method = &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;RemotingServices&lt;/font&gt;&lt;font size="2"&gt;.GetMethodBaseFromMethodMessage((&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;IMethodMessage&lt;/font&gt;&lt;font size="2"&gt;)msg);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;FormatExceptionAttribute&lt;/font&gt;&lt;font size="2"&gt; formatException = (&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;FormatExceptionAttribute&lt;/font&gt;&lt;font size="2"&gt;)&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;Attribute&lt;/font&gt;&lt;font size="2"&gt;.GetCustomAttribute(method, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;typeof&lt;/font&gt;&lt;font size="2"&gt;(&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;FormatExceptionAttribute&lt;/font&gt;&lt;font size="2"&gt;));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;LogExceptionAttribute&lt;/font&gt;&lt;font size="2"&gt; logException = (&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;LogExceptionAttribute&lt;/font&gt;&lt;font size="2"&gt;)&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;Attribute&lt;/font&gt;&lt;font size="2"&gt;.GetCustomAttribute(method, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;typeof&lt;/font&gt;&lt;font size="2"&gt;(&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;LogExceptionAttribute&lt;/font&gt;&lt;font size="2"&gt;));&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&amp;nbsp; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ReturnMessage&lt;/font&gt;&lt;font size="2"&gt; response = (&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;ReturnMessage&lt;/font&gt;&lt;font size="2"&gt;)&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;.nextMessageSink.SyncProcessMessage(msg);&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&lt;/font&gt;&lt;font size="2"&gt; (response.Exception == &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;font size="2"&gt;) &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;font size="2"&gt; response; &lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string&lt;/font&gt;&lt;font size="2"&gt; message = response.Exception.Message;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&lt;/font&gt;&lt;font size="2"&gt; (formatException != &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;font size="2"&gt;) message = formatException.FormatException(response.Exception);&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&lt;/font&gt;&lt;font size="2"&gt; (logException != &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;font size="2"&gt;) logException.Process(message);&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/font&gt;&lt;font size="2"&gt; response;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;IMessageCtrl&lt;/font&gt;&lt;font size="2"&gt; AsyncProcessMessage(&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;IMessage&lt;/font&gt;&lt;font size="2"&gt; msg, &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;IMessageSink&lt;/font&gt;&lt;font size="2"&gt; replySink)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;.nextMessageSink.AsyncProcessMessage(msg, replySink);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;As you can see, in this aspect, we get a reference to the method and&amp;nbsp;check for&amp;nbsp;possible attributes ([LogException] and [FormatException]) and run the rest of the chain. At this point in execution, exceptions do not get thrown, so there is no need for any try/catch constructs. Simply check the resulting message for exceptions, and if any are detected, format and log the exception if the function has been decorated with attributes directing the aspect to do so.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;As you can see in the above example, I have introduced another attribute called [FormatException]. This is simply to illustrate that multiple attributes can be associated with the aspect and you can decorate your functions as desired with one, both or neither directives for the aspect to adhere to. Here is the definition for [FormatException]:&lt;/font&gt;&lt;/p&gt;&lt;font size="2"&gt;&lt;font color="#0000ff" size="2"&gt;
&lt;p&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;FormatExceptionAttribute&lt;/font&gt;&lt;font size="2"&gt; : &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;Attribute&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; FormatException(&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;Exception&lt;/font&gt;&lt;font size="2"&gt; exception)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;EventFormatter&lt;/font&gt;&lt;font size="2"&gt;().FormatException(exception);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;and the definitions for the logger and event formatter:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt;&lt;font size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;EventLogger&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt; LogMessage(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; message)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;Console&lt;/font&gt;&lt;font size="2"&gt;.WriteLine(&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;Logging exception: &amp;quot;&lt;/font&gt;&lt;font size="2"&gt; + message);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff" size="2"&gt;
&lt;p&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;EventFormatter&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; FormatException(&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;Exception&lt;/font&gt;&lt;font size="2"&gt; exception)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;Formatted Exception: &amp;quot;&lt;/font&gt;&lt;font size="2"&gt; + exception.Message;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;If I add [FormatException] in my Messenger class, the output changes to:&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;Attempting connection...&lt;br /&gt;&lt;font size="2"&gt;Logging Exception: Formatted Exception: A problem occurred!&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="5"&gt;
&lt;p style="FONT-SIZE:24px;"&gt;&lt;br /&gt;In Closing&lt;/p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="5"&gt;&lt;/font&gt;I see some nice benefits and some unfortunate drawbacks to the way .NET handles this. The need to inherit from ContextBoundObject is something I really don&amp;#39;t like and causes me to be hesitant&amp;nbsp;in trying to implement something like this. Additionally, it would require a certain level of competancy for anyone that wants to maintain this code. However, this does prevent a lot of try/catch/log exception/throw; code repetition and could be altered to allow one to easily inject whatever sort of logging/formatting mechanisms they want to use, or even actions they want to take based on type of exception. Furthermore, it allows developers to write try/catch statements only in cases where they want to handle exceptions and resolve them, and it allows developers that use it to focus on writing code to accomplish the task at hand instead of writing code (yet again) to log exceptions that arise in the system.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Aspect-oriented+approaches+to+software+development&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2007%2f10%2f25%2faspect-oriented-approaches-to-software-development.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2007%2f10%2f25%2faspect-oriented-approaches-to-software-development.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=1145" width="1" height="1"&gt;</content><author><name>mbratton</name><uri>http://www.lostechies.com/members/mbratton/default.aspx</uri></author></entry><entry><title>What does that function do, really?</title><link rel="alternate" type="text/html" href="/blogs/marcus_bratton/archive/2007/08/02/what-does-that-function-do-really.aspx" /><id>/blogs/marcus_bratton/archive/2007/08/02/what-does-that-function-do-really.aspx</id><published>2007-08-03T02:06:00Z</published><updated>2007-08-03T02:06:00Z</updated><content type="html">&lt;p&gt;Recently, I had&amp;nbsp;the chance to read a blog by one of my former coworkers on the topic of &lt;a class="" title="code duplication and functional programming" href="http://anydiem.com/2007/07/31/some-functional-programming-in-c-20/" target="_blank"&gt;code duplication and functional programming&lt;/a&gt;. I found the&amp;nbsp;ideas there interesting; in many applications that I deal with&amp;nbsp;there are&amp;nbsp;certain repeated processes. For example,&amp;nbsp;functions try a certain statement,&amp;nbsp;catch a possible exception and log the information to the event log. Pretty standard process. So in reading this blog I came to a simple conclusion. There are at least two types of code that&amp;nbsp;are duplicated: Functional Code and Procedural Code (not to be confused with functions and procedures). One of them is often refactored and reused... one of them is not. Take the following code example:&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;
&lt;p&gt;public&lt;font color="#000000" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;font color="#000000" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;font color="#008080" size="2"&gt;DataManager&lt;/font&gt;&lt;font color="#000000"&gt;&lt;font size="2"&gt;&amp;nbsp;&lt;br /&gt;&lt;/font&gt;{&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/font&gt;&lt;font color="#000000" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#000000"&gt; SaveData()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; try&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Do something&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;catch&lt;/font&gt;&lt;font size="2"&gt;(&lt;/font&gt;&lt;font color="#008080" size="2"&gt;Exception&lt;/font&gt;&lt;font size="2"&gt; ex)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#008080" size="2"&gt;EventLogger&lt;/font&gt;&lt;font size="2"&gt;&amp;nbsp;logger = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#008080" size="2"&gt;EventLogger&lt;/font&gt;&lt;font size="2"&gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; logger.LogException(ex);&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/p&gt;&lt;/font&gt;
&lt;p style="FONT-SIZE:24px;"&gt;Functional Code&lt;/p&gt;
&lt;p&gt;Functional code is&amp;nbsp;code that accomplishes a certain task. In this example, I have intercepted an exception in the system and I am going to log it to the event log. So I write a class&amp;nbsp;with a&amp;nbsp;method that takes messages in and inserts them into the event log. This code fulfills a function in this system -- it ensures that messages it receives are persisted in the designated medium (the event log, in this case). Duplicate code here is easily refactored into an object that provides an interface to the event log, with methods for managing events and it acts as an application boundary for the system. The segments of code within the try, and within the catch are functional code segments.&lt;/p&gt;
&lt;p style="FONT-SIZE:24px;"&gt;Procedural Code&lt;/p&gt;
&lt;p&gt;Procedural code is code that governs how your functional code is implemented. This code fulfills a process of the system -- it ensures that when an exception occurs, the appropriate piece of functional code is executed. In the above example, this is the code that manages when your event logging class is used -- it is the code that tries a statement, catches some exception, and invokes the logger.&amp;nbsp; It&amp;#39;s something seen repeated in a lot of functions in a lot of applications. &lt;/p&gt;
&lt;p&gt;Reading the above blog, I thought it was a neat way to refactor this into a reusable process. But, I felt that while the procedural code had been abstracted a bit, calls to it would still be scattered through my systems, and I was hoping to remove it from my implementation all together.&lt;/p&gt;
&lt;p&gt;So why is this important? By refactoring functional code into reusable objects, you can change the internal implementation of that object without impacting the rest of your system. But what about the steps your system takes in order to fulfill that function? What if you want to amend that process to do additional steps before logging that exception?&lt;/p&gt;
&lt;p&gt;Often times this sort of code is placed upon the object that is performing the function itself. Let&amp;#39;s amend my original example of event logging to include message formatting. In our modified example, the object&amp;#39;s behavior is defined as accepting a message, &lt;em&gt;formatting that message, &lt;/em&gt;and then logging it. While the formatting of the message is clearly procedural -- it is a step the system takes to prepare for logging -- many people will dump it with functional code. Take for example, the following sample:&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;
&lt;p&gt;public&lt;/font&gt;&lt;font color="#000000" size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;font color="#000000" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;font color="#008080" size="2"&gt;EventLogger&lt;/font&gt;&lt;font color="#000000" size="2"&gt; &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;{&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt; LogException(&lt;font color="#0000ff" size="2"&gt;Exception&lt;/font&gt;&lt;font size="2"&gt; exception&lt;/font&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string&lt;/font&gt;&lt;font size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;message =&amp;nbsp;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;new&lt;font size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;ExceptionFormatter().FormatExceptionMessage(exception);&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this&lt;/font&gt;&lt;font size="2"&gt;.&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;WriteToEventLog(message);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Alternatively, you could pass the appropriate formatter to the function:&lt;/p&gt;
&lt;p&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt;&lt;font color="#000000" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;font color="#000000" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;font color="#008080" size="2"&gt;EventLogger&lt;/font&gt;&lt;font color="#000000" size="2"&gt; &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;{&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt; LogException(&lt;font color="#0000ff" size="2"&gt;Exception&lt;/font&gt;&lt;font size="2"&gt; exception,&amp;nbsp;&lt;font color="#0000ff"&gt;IExceptionFormatter&lt;/font&gt;&lt;font size="2"&gt; formatter&lt;/font&gt;&lt;/font&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string&lt;/font&gt;&lt;font size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;message =&amp;nbsp;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;font size="2"&gt;formatter.FormatExceptionMessage(exception);&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this&lt;/font&gt;&lt;font size="2"&gt;.&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;WriteToEventLog(message);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;This intially seems to make sense to do.&amp;nbsp;The first example&amp;nbsp;reduces code duplication because the presumption is that all error messages will need to be formatted before being logged. However, from the standpoint of the consumer of this class,&amp;nbsp;one would expect this method to take an exception and send it to the event log.&amp;nbsp;One would not be aware that formatting would be occuring on&amp;nbsp;the message. This design produces unexpected behavior from the standpoint of the consumer and becomes an implicit and non self-documenting aspect of the object.&amp;nbsp;Although it&amp;nbsp;clearly logs messages to the event log, it also has unclear additional behavior. Furthermore, if a developer implements the second sample, the consumer also has to be aware of&amp;nbsp;exception formatting in order to log messages,&amp;nbsp;resulting in&amp;nbsp;a more difficultly consumed interface. One could simply rename the method in either sample to &amp;quot;FormatAndLogMessage&amp;quot;, but honestly this addresses the symptom of the problem, and not the problem itself.&lt;/p&gt;&lt;/font&gt;
&lt;p style="FONT-SIZE:24px;"&gt;The Seperation of Concerns&lt;/p&gt;
&lt;p&gt;What I&amp;#39;m getting around to is that there is a clear seperation of concerns here. Event Logging should not be concerned with Message Formatting. These are seperate concerns and the functional code to fulfill each concern should&amp;nbsp;be ignorant&amp;nbsp;of the other. This would imply that the procedural code in first sample should somehow be amended in the try/catch to perform message formatting before logging. If logging were performed like this throughout the system, this approach would actually increase code duplication instead of solve it! Furthermore, one would expect a function like SaveData() would simply do as it says -- save the data. However in our above sample, the seperation of concerns is apparently violated by the fact that SaveData() not only saves information, it logs exceptions to the event log!&lt;/p&gt;
&lt;p&gt;Fortunately, there is a way to resolve this issue in a relatively simple manner, reducing procedural code duplication and&amp;nbsp;seperating concerns within our functional code segments while producing a readable, self-documenting interface. This can be accomplished declaratively by use of attributes.&lt;/p&gt;
&lt;p style="FONT-SIZE:24px;"&gt;[Loggable] and [LogException]&lt;/p&gt;
&lt;p&gt;Assume for a moment that the above scenario could be implemented in this fashion:&lt;/p&gt;
&lt;p&gt;&lt;font color="#0000ff"&gt;&lt;font color="#000000"&gt;[Loggable]&amp;nbsp;&lt;/font&gt;&lt;br /&gt;public&lt;font color="#000000" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;font color="#000000" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;font color="#008080" size="2"&gt;DataManager&lt;/font&gt;&lt;font color="#000000"&gt;&lt;font size="2"&gt;&amp;nbsp;&lt;br /&gt;&lt;/font&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[LogException]&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;font color="#000000" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#000000"&gt; SaveData()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&amp;nbsp;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Do something&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#000000" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;/font&gt;&lt;font color="#000000" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;This implementation is a much simpler, more elegant way to address the problem. In this example, there is no procedural code within SaveData(), only functional code. Exception logging has been abstracted away from our codebase and reclassified as a system concern. This is a good thing -- it allows our code to focus purely on the needs of the business instead of having to also manage the needs of the system.&amp;nbsp;In this implementation&amp;nbsp;we have extended the way in which the system is expected to address&amp;nbsp;exceptions during execution declaratively, augmenting&amp;nbsp;the way in which our code executes without&amp;nbsp;affecting the way our code is implemented.&lt;/p&gt;
&lt;p&gt;So what about exception formatting? Using this approach, we should easily be able to extend our design to address this concern as well.&lt;/p&gt;
&lt;p&gt;[Loggable]&amp;nbsp;&lt;br /&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt;&lt;font color="#000000" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;font color="#000000" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;font color="#008080" size="2"&gt;DataManager&lt;/font&gt;&lt;font color="#000000"&gt;&lt;font size="2"&gt;&amp;nbsp;&lt;br /&gt;&lt;/font&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[FormatException, LogException]&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;font color="#000000" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#000000"&gt; SaveData()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&amp;nbsp;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Do something&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#000000" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;/font&gt;&lt;font color="#000000" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;or, if you prefer to use more than one formatter:&lt;/p&gt;
&lt;p&gt;[Loggable]&amp;nbsp;&lt;br /&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt;&lt;font color="#000000" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;font color="#000000" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;font color="#008080" size="2"&gt;DataManager&lt;/font&gt;&lt;font color="#000000"&gt;&lt;font size="2"&gt;&amp;nbsp;&lt;br /&gt;&lt;/font&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[FormatException(&lt;font color="#0000ff"&gt;typeof&lt;/font&gt;(ExceptionFormatter)), LogException]&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;font color="#000000" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#000000"&gt; SaveData()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&amp;nbsp;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Do something&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#000000" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;/font&gt;&lt;font color="#000000" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;This allows us to identify both exception message formatting and exception logging as procedural aspects of our system and abstract those concepts away from our functional code declaratively, producing less code to maintain through code reuse and more readable code by focusing our written code on what is important -- the functionality. &lt;/p&gt;
&lt;p&gt;So how useful is this? Fairly useful, in my opinion. It would allow developers to draw clear distinctions declaratively between system needs and business needs. Operations like event logging,&amp;nbsp;operation retrying and using transactions are some easy examples of where this could be implemented to reduce code duplication. The key is knowing when and what types of procedural code make good candidates for this sort of approach.&lt;/p&gt;
&lt;p&gt;In my next post, I will show how the procedural code in our first sample is abstracted into attribute usage and implemented in .NET to produce the final examples, touching on something I came across while trying to figure out how to accomplish this -- Aspect Oriented Programming.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=What+does+that+function+do%2c+really%3f&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2007%2f08%2f02%2fwhat-does-that-function-do-really.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmarcus_bratton%2farchive%2f2007%2f08%2f02%2fwhat-does-that-function-do-really.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=373" width="1" height="1"&gt;</content><author><name>mbratton</name><uri>http://www.lostechies.com/members/mbratton/default.aspx</uri></author></entry></feed>