Singleton Pattern in WCF Service

Sometimes it’s appropriate to have exactly one instance of a class: window managers, print spoolers, and file systems are prototypical examples. Typically, those types of objects—known as singletons—are accessed by disparate objects throughout a software system, and therefore require a global point of access. Of course, just when you’re certain you will never need more than one instance, it’s a good bet you’ll change your mind. As a part of performance tuning with our WCF application it is observed that we need to make sure only one instance of service is running and it is not trying to create each instance while making each service call.
The Solution:
The singleton pattern is one of the best-known patterns in software engineering. Essentially, a singleton is a class which only allows a single instance of itself to be created, and usually gives simple access to that instance. A single service instance no matter how many clients call the service might seem like an interesting option since it won’t use up many resources. The drawback however is that you can have multiple calls from multiple clients at the same time. All those calls will be handled by the same service instance. If you only allow one single thread to access the service instance this will drastically reduce the performance. To speed things up you quickly wind up dealing with multiple threads and the obligatory synchronization that ensues.
Singleton Services
The singleton service is the ultimate shareable service. When a service is configured as a singleton, all clients get connected to the same single well-known instance independently of each other, regardless of which endpoint of the service they connect to. The singleton service lives forever, and is only disposed of once the host shuts down. The singleton is created exactly once when the host is created.You can configureasingleton service by setting the InstanceContextMode property to InstanceContextMode.Single:
While every application is unique when it comes to scalability, performance, and throughput, Windows Communication Foundation does offer canonical instance management techniques that are applicable across the range of applications, thus enabling a wide variety of scenarios and programming models. Understanding Windows Communication Foundation instance management and choosing the right activation mode is critical.WE have taken this approach to address the issues in our application.

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,
        ConcurrencyMode = ConcurrencyMode.Multiple)]

Also please see the sample code for implementing

     public class Singleton
     {
       private static Singleton objInstance;
        private Singleton()
        {

        }
        public static Singleton GetInstance()
        {
            if (objInstance == null)
            {
                objInstance = new Singleton();
            }
            return objInstance;
        }
    }
Advertisements

Rapid Application Development (RAD)

Rapid Application Development (RAD)
Software prototyping, refers to the activity that occurs during certain software development and responsible for creating prototypes of software applications. This is a big and deep topic to discuss regarding prototyping; I would like to limit the scope by only discussing one of the models – Rapid prototyping Model (RAD), which we have come across in one of our deliverables.
Why RAD?
Due to the intense competition in software, products that are successful in the marketplace are:

Functional,
Reasonably priced, and
Easy to learn and use.

Pricing aside, it is difficult and time-consuming to develop products with these characteristics. However, one way to minimize effort and time spent is to use the rapid prototyping process of product development.
RAD (Rapid prototyping Model)
Rapid prototyping is a process of software development wherein physical objects are automatically constructed by means of SFF or solid freeform fabrication. In the process of rapid prototyping, a prototype or working model can be constructed quickly, and tested for its functionality, performance and output. The new features or ideas can be illustrated well in the prototype and early user feedback can be gathered with regards to the product.
There are numerous advantages of rapid prototyping. Rapid prototyping involves creating a realistic model of a product’s user interface to get prospective customers involved early in the design of the product. Using rapid prototyping, you model the look and feel of the user interface without investing the time and labor required to write actual code. Then you show the prototype to prospective customers, revise the prototype to address their comments, and keep repeating these two steps. Your goal is to produce a complete, agreed-upon design of the product’s user interface before writing a single line of actual code. When walkthroughs and usability tests show you that customers are delighted with your prototype user interface, then programmers can model it when they code the actual product.
RAD uses minimal planning in favor of rapid prototyping. The “planning” of software developed using RAD is interleaved with writing the software itself. The lack of extensive pre-planning generally allows software to be written much faster, and makes it easier to change requirements. So here I don’t want to come down and explain under what scenario we have to go with RAD. the description itself is clean and transparent. It is nothing but a WYSIWYG process where the virtual model and the physical model are almost identical. WYSIWYG: WYSIWYG as the abbreviation for ‘What You See Is What You Get’. It is used in ‘computing’ for describing a system wherein content looks similar to final product at the time of editing. It is generally used in word processors. However, this use is in the form of HTML (Web) authoring.
The word “rapid” is relative: construction of a model with contemporary methods can take from several hours to several days, depending on the method used and the size and complexity of the model. Additive systems for rapid prototyping can typically produce models in a few hours, although it can vary widely depending on the type of machine being used and the size and number of models being produced simultaneously.Giving the flow chart for detail reference

Experience 3 tier architecture

There are lot internet information’s on 3 tier architecture. I don’t want to add one more on top of it to spam a Google query! This is only to drow my experience on 3 tier architechure.
Dot NET framework and Visual Studio present many choices for choosing the right architecture from placing the data access code directly in the UI through datasets as well as separating all these code in a reusable component nothing called layers. Like any other developer I also come across to select 3 tiers in my application so want to share my experiences in this. Here I need to come up with an application where the presentation layer needs to extract information from a backend database, the presentation would utilize a series of layers to retrieve the data, rather than having the database calls embedded directly within itself. So that I can use be reused this components as well as will end up an easy maintaince.There may be also chances was there but some of the functionality may later be moved to a smart client application. Portions of an application may be split between a web site and a web or windows service that runs on a server.Likewice so many reasons was there to select three tiers as application architecture for our development. Rather than explain the reason I would like to take you how we went ahead and implemented in our application.
As one of the greatest advantages we have split the layers between developers across the location and started development parallel among 12 member team. As each layer complete with their development we have integrated the code and shaped to complete application! Simple approach right?
For more details and samples please read my blog:

http://jijo-vg.blogspot.com/2010/05/experience-3-tier-architecture.html