So most people would have already figured this out, but I thought I would post up about it anyway. The proxies generated by svcutil.exe in Indigo derive from ProxyBase<T> where T is an interface with a ServiceContract attributed.

One of the things that I like to do is figure out how to build up a proxy from scratch to see what all the critical pieces of the service model are from a client perspective (since normally the generated code includes more than it has to). So in the example below I contstruct an instance of MathProxy which derives from ProxyBase<T>, passing in IMath (service contract/interface) as the type parameter.

The type parameter is used to build an InnerProxy which implements the IMath interface. Then all you have to do is create wrapper methods which call that interface. Also note that I pass the contruction call to the protected ProxyBase(Binding) constructor. You need to specify the binding you are going to use up from to correctly configure the proxy.

IndigoProxyFromScratch

I’m looking forward to posting up more about Indigo (and Avalon) as I start understanding the models that support the abstraction.

Who is John Galt?

May 28, 2005

I just finshed reading Ayn Rand’s Atlas Shrugged. This book has been recommended to me several times over the past eight or so years but I tend not to take much time to read many books other than technical references, although I have taken the time to read things like the Harry Potter and Artemis Fowl series, and even re-read some of Issac Asimov’s works. But I should have read Atlas Shrugged earlier.

The book is extremely powerful but very difficult to penetrate so you really have to WANT to read it. I read quite slowly so this 1000+ page volume has taken me a few months to get through with casual reading. The book really has layers, one layer is pure story with characters, plot, love and war – the other layer is a manifesto for life.

The funny thing is that I don’t think anyone would enjoy both layers at the same time (I could be wrong but thats what I felt). I was most interested in the philosophical aspects of the book because it is helping me deal with some issues that I am trying deal with at the moment. It certainly helps put things into perspective.

So I’ve done the math, if I do just one class a day I am going to be at this for decades given the size and scope of the .NET type-system. In fact its worse than that because between .NET 1.x and 2.0 the size of the out-of-the-box class library effectively doubled and if I included all thats coming in WinFX in my TODO list then I’ll never get done. The great thing about my original goal was that I wasn’t going to talk about every class on this blog.

Anyway – I did want to do a pretty quick post about the System.Activator class. The Activator class is one of those useful types which would be used in pretty much every enterprise scale .NET application around, both inside the Framework itself but also directly by developers like you and me. Its role in life is basically to support the instansiation of objects whether they be PONO (Plain Old .NET Objects), COM objects are even remote objects exposed by the .NET Remoting plumbing. To support that there are three main methods – CreateInstance(…), CreateComInstanceFrom(…) and GetObject(…), each with their own set of overloads.

Now – in .NET 2.0 there has been a couple of modifications (from a public API point of view) to the Activator class so that now there is actually a generic CreateInstance method. Now the curious thing is that this won’t necessarily help people who are using the CreateInstance method to do things like plug-in loading because you actually have to have the type information you are want to create an instance available at compile time. So effectively this:

SomeType instance = Activator.CreateInstance<SomeType>();

Is the same as this:

SomeType instance = new SomeType();

So you are probably asking the why question now right? A not-so-old wise man once said to me – “I don’t answer why questions”. Unfortunately I’m not going to take his advice and instead I’m going to try and speculate where this method might be useful – I’m thinking generic factory classes which attach background behaviours to the types they create. Here is a trivial example.

GenericCreateInstanceUseCase

Now I don’t necessarily recommend spinning up a thread for every object you create in everyday code but I wanted to illustrate a concept. The use of anonymous methods was pretty cute though don’t you think?

P.S. I knew it – CreateProcess<T> is used inside System.ServiceModel in Indigo. I guessed, checked and was right. It just strikes me as the kind of place you would want to do the kind of interception that this little fella allows.