Posts
58
Comments
103
Trackbacks
10
Sunday, October 21, 2007
Every Class Should Be a WCF Service

Actually, no.  Just kidding. ;-)

BUT, that's the view held by a very smart architect from a different school of thought.  We can break down his thoughts a bit further though.  You see, he thinks every class is/should be a component.  So what he's really trying to say is that every component should be a wcf service.  Why?  Because the component services provided by WCF can interop with other languages (if necessary).  This comes via the WS-Death Star.

But don't take my word for it, watch Ron Jacobs interview Juval Lowey.  And close your ears when you hear the comment about TDD.  Don't flip the bozo bit.  He's a really sharp guy.

And remember, if anyone outside Microsoft would be capable of making such a claim about WCF, it would be the RD of Silicon Valley, who was one of the few outside Microsoft to help design WCF.

It may seem like overkill now, but maybe not when processors start shipping with 32 cores on them.

posted @ Sunday, October 21, 2007 9:05 PM | Feedback (1)
DomainService.Equals(typeof(Component))

I just wanted to point this out for anyone else who hasn't already noticed.  Domain Services are usually components in disguise (ie..same thing, different terminology).

While a lot of emphasis is put on statelessness for components, there is actually a finer grained definition.

A class is a component if its clients can be instance agnostic.

Whether it's an IEmailSender or an interface for a remote service, your application typically does not care which instance of the proxy or helper class it gets.  In terms of state, it's less about not having state and more about not having internal state.

For example, Data Access Components are allowed to have external state.  Their state is stored in the form of the database.  The fact that they appear to have state (the data in the database) does not breach the component definition.  The reason is that since the state is centralized and external, the clients are instance agnostic.  This falls within the guidelines of component-orientation.

Much like the guys building component architectures, we too use classes whose clients are instance agnostic.  Service Layer classes are components.  Domain Service classes are also components.  There are no rules as to how a component is built out internally (procedurally, functionally, object-oriented), etc.  Those are just the implementation details.  I use an implementation of the Notification Pattern for Dto validation.  It too is a component.

Anything you are injecting today is very likely a component.  You can inject state into classes using tools like Windsor, but it's not easy (and involves injecting a properties hashtable--no thanks).

Oh, and those "configuration" variables don't count as state either (ie..SmtpServer).  Those are perfectly valid in both paradigms.

Domain model applications are really component sandwiches, where the OOP/Domain Model is the meat.

What about NHibernate?  The SessionFactory is a component--although you only ever want one instance per application.  This is perfectly valid as well.

Sessions are a little bit trickier.  Each Session has a unique state.  This can still be accounted for if the session state were externalized to the session class.  COM+ did the equivalent thing with transactions.  In that case, components were used inside a "transaction stream".  The statefulness (ie..the current transaction) become a part of the Context (the environment).  The clients were instance agnostic, but the behavior of the instance changed slighly based on the particular context of execution.  The same technique could be used of NHibernate sessions if the state was externalized (ie..into the Request Cache in ASP.NET).  Then the clients could be instance agnostic and the Session would become a component.  The same can be said of a Session's database connection and transaction.  Another alternative (which I've seen several people do) would be to encapsulate the Session as state of a larger component (say..a Repository class).  The Repository becomes a component.  The Session becomes a part of the execution context (the environment).  This would allow multiple clients to use the same Repository instance, with the behavior varying slighly based on context.

posted @ Sunday, October 21, 2007 3:43 PM | Feedback (0)
The Insanity and the Irony

Here are a couple interesting questions to ask youself.

  • Could Windsor be extended to inject a Java dependency into my class?  This would involve adding some distributed computing code to Windsor.  The code would have to be very standards-compliant for the interop scenario.
  • Could a WCF Service host inject class dependencies into my service layer classes?
  • Could WCF or Windsor be extended to provide event-based mediation between two decoupled classes?

You see, not many people have noticed, but there is a common thread of thought amoung these very different technologies.  One groups works over there and uses one set of terminology.  Another group works elsewhere using a different set of terminology.

I would like to fundamentally challenge each and every person who reads this post on their view of WCF, COM+, and Windsor.

Context-Based Class Services

You see, each of the three technologies rely on the same underlying ideas--even if they have different names.  They all manage the environment in which a class instance runs.

WCF manipulates the environment (think behaviors and binding) to enable distributed computing.  It does this to handle interop scenarios (ie..with Java).  It does this to handle various activation scenarios (singleton anyone?).  It handles transactions.  It also handles a whole host of other things.  Some would argue that WCF works quite well even for services on a single server (they do have an named pipes transport after all).

Windsor manipulates the environment (think Castle.DynamicProxy) to provide a very similar set of context-based services.  It handles lifestyles (singleton anyone?).  It can handle transactions (with a little extra help).  And it handles a whole host of other things (not to mention IoC).

COM+ also manipulates the environment (using Contexts) to provide a nearly identical stack of services as WCF and Windsor.  Transactions?  Yep.  Activation/Lifestyles? Yep.

Yes, windsor is much more light weight.  That's beside the point.  These three things are all built on the exact same patterns.

They all value configuration over code (which is slightly different than the ruby value statement).

If you are using Windsor today, is there a reason why WCF couldn't replace Windsor in your codebase (if someone were to create both local and remote IoC behaviors)?  Remote dependency injection, now there's a concept.  What if your Windsor configuration was replaced by a centralized repository (ie..a service which might live on another machine) that was used to resolve dependencies?  What if Windsor understood UDDI for configuration?

If you are using WCF today, is there a reason that Windsor couldn't replace WCF if there was a remoting-type stack built into Windsor?  What if Windsor could interop with Spring.NET?  It parallels the Java/.NET Interop of WCF.

Ironically enough, even COM+ had publish/subscribe.  Neither Windsor nor WCF offer any type of publish/subscribe facilities/bindings.

At some point, these things need to converge.  They all do the same thing.  WCF was an evolution of COM+, but we still see sets of features that are missing.

The truth is, they all provide Component Services.

What if Microsoft built local and remote IoC into WCF?  What if that also included basic Pub/Sub?

posted @ Sunday, October 21, 2007 1:20 AM | Feedback (4)