|
|
||
|
Activity:
1 comments
169 views
last activity : 07 06 2010 20:18:04 +0000
|
||
|
|
Many times we come across a situation where we want to have a some way to create instance of related classes. Using Factory Method pattern we can achieve this.
Main Parts of this pattern are,
- Product(Interface - IController)
- Concrete Product(MainController, LoginController etc.. implementing IController i.e. Product)
- Creator(IControllerCreatorHelper)
- ConcreteCreator(CControllerInstanceCreator)
While Implementing MVC pattern for one of my project, i came across a situation where i required generalized mechanism to create a singleton instance of a every Controller class.
For this i started creating a hierarchy for Controller classes where every Controller class has to implement IController interface.
public interface IMainController:IController
{
___________
___________
}
public class MainController: IMainController
{
public static IMainController Instance
{
get
{
return(IMainController)CControllerInstanceCreator<MainController>.Instance;
}
}
}
internal class CControllerCreatorHelper:IControllerCreatorHelper
{
#region IControllerCreatorHelper Members
public IMainController CreateMainControllerInstance()
{
return MainController.Instance;
}
#endregion
}
public class CControllerInstanceCreator where T : IController, new()
{
private static T m_oController;
private static object syncRoot = new Object();
public static IController Instance
{
get
{
if (m_oController == null)
{
lock (syncRoot)
{
m_oController = new T();
}
}
return m_oController;
}
}
}
By reading the code you can observe CControllerCreatorHelper class contains a method for every controller to return the singleton instance. CControllerInstanceCreator class actully returns a singleton instance of any type implementing IController interface.
For more information on Factory method pattern plz. visit
http://www.dofactory.com/Patterns/PatternFactory.aspx

|
|
|
|
|
|
|
|
|
|
Many times we come across a situation where we want to have a some way to create instance of related classes. Using Factory Method pattern we can achieve this. Main Parts of this pattern are, Product(Interface - IController) Concrete... |
This article promotes the practical approach using generics collections. Working across the project while reviewing the code i came to know the beauty of using generics. I will guide you through how to replace the collections with generic... |
ok.... cool.... But did you get the exact reason for session time out?... Again You can try out calling webservice method asynchronously if possible. Tkcr Welcome |