1. Kamyar Inanloo
  2. LiteRpc.Client

Commits

Kamyar Inanloo  committed e4e2bb9

Fixed non-generic singleton class.

  • Participants
  • Parent commits b6343ee
  • Branches default

Comments (0)

Files changed (2)

File LiteRpc.Client/Setup.cs

View file
 {
 	using System;
 	using System.Collections.Generic;
-	using Castle.DynamicProxy;
 	using System.Configuration;
 	using System.Net;
+	using Castle.DynamicProxy;
 
 	public static class Setup
 	{
 
 				ServiceParams[typeof(T)] = info;
 
-				Singletone<T>.SetInstance(proexyGen.CreateInterfaceProxyWithoutTarget<T>(interceptor));			
+				Singletone<T>.SetInstance(proexyGen.CreateInterfaceProxyWithoutTarget<T>(interceptor));
 			}
 			return Singletone<T>.Instance;
 		}
 		}
 
 		public static object CreateProxyFor(Type type)
-		{
-			if (Singletone.Instance == null)
+		{			
+			if (Singletone.InstanceOf(type) == null)
 			{
-
 				var proexyGen = new ProxyGenerator();
 				var info = new ServiceInfo();
 
 
 				Singletone.SetInstance(proexyGen.CreateInterfaceProxyWithoutTarget(type, interceptor));
 			}
-			return Singletone.Instance;
+			return Singletone.InstanceOf(type);
 		}
 
 		public static object CreateProxyFor(Type type, ICredentials credentials)

File LiteRpc.Client/Singletone.cs

View file
 namespace LiteRpc.Client
 {
 	using System;
+	using System.Collections.Generic;
 
 	internal class Singletone<T>
 	{
 
 	internal class Singletone
 	{
-		private static object instance;
+		private static Dictionary<Type, object> instanceContainer = new Dictionary<Type, object>();
 
-		public static object Instance
+		public static object InstanceOf(Type t)
 		{
-			get
+			if (instanceContainer.ContainsKey(t))
 			{
-				return instance;
+				return instanceContainer[t];
+			}
+			else
+			{
+				return null;
 			}
 		}
 
 		public static void SetInstance(object value)
 		{
-			instance = value;
+			instanceContainer[value.GetType()] = value;
 		}
 	}
-
 }