Archive for May, 2009

I have recently downloaded the Visual Studio 2010 Beta 1 and started looking into the .NET Framework 4.0/IDE features.In the next couple of posts I will be discussing about these.To start with I have chosen optional parameters and default values.This feature is nothing new and has been there in languages like C++ for quite long.We will first take a look how we can use this in C# and how it is implemented.The following lines of C# code shows a method where the parameter middleName is optional and client is forced to pass a blank string value there as the parameter is not optional.
(more…)

Advertisements

In my last post I had started writing about Instance Pooling in WCF and we ended up developing a simple class providing object pooling functionality.In this post we will see what needs to be done step by step to incorporate this instance pool into the WCF framework.

Implementing IInstanceProvider

The class System.Runtime.Dispatcher.DispatchRuntime exposes the property InstanceProvider of type IInstanceProvider.DispatchRuntime uses this instance to acquire and release instances of service objects.IInstanceProvider defines the following methods:

  • GetInstance – Returns an service object instance
  • ReleaseInstance – Releases a service object instance

(more…)

In my earlier post on WCF behaviors I had given some code snippets on how we can implement pooling in WCF using Behaviors.In this series of posts I am planning to elaborate on the implementation on the same.So to start with the question What is Pooling? needs to be answered.Pooling is a technique where resources are recycled to avoid expensive creation and release of resources.Once the resources are recycled and sent back to pool they lose all their state and identity and are ready to be used again.

To start with first I have defined an interface IResourcePool which defines the contract to acquire and release an object back to the pool.

public interface  IResourcePool
{
    object Acquire();
    void Release(object resource);
}

(more…)

In my last post I had completed the demo of building a layered ASP.NET MVC application(the bookmark list application).This week I thought of adding the StructureMap container to that demo.I am quite new to StructureMap but I loved it’s usage of Fluent Interfaces and DSL a lot.I have primarily applied what I understood from it’s online documentation.I wanted to keep the option of plugging in another container later in this application.So I defined my own container interface as shown below:

    public interface  IContainer {
       
void AddInstanceConfig<I, T>(string key) where T:I; //Configures an instance with instance key,type and concrete type
       
void StartContainer(); //Starts the Container
       
object GetInstance<I>(string instanceName); //Returns an object instance based on the instance key/name
       
void DestroyContainer(); //destroys the container and releases the references

(more…)