ClientChannel

 1 /// <summary>
 2     /// TODO: Elegant
 3     /// </summary>
 4     /// <typeparam name="TInstance"></typeparam>
 5     /// <typeparam name="TContract"></typeparam>
 6     public class ClientChannel<TInstance, TContract>
 7         where TInstance : ClientBase<TContract>, new()
 8         where TContract : class
 9     {
10         private TInstance proxy;
11         private static ClientChannel<TInstance, TContract> instance;
12 
13         public static ClientChannel<TInstance, TContract> Instance
14         {
15             get { return ClientChannel<TInstance, TContract>.instance; }
16             set { ClientChannel<TInstance, TContract>.instance = value; }
17         }
18 
19         public TInstance Channel
20         {
21             get { return proxy; }
22             set { proxy = value; }
23         }
24 
25         static ClientChannel()
26         {
27             instance = new ClientChannel<TInstance, TContract>();
28         }
29 
30         private ClientChannel()
31         {
32             proxy = new TInstance();
33             proxy.InnerChannel.Faulted += new EventHandler(ClientChannel_Faulted);
34         }
35 
36         void ClientChannel_Faulted(object sender, EventArgs e)
37         {
38             proxy.InnerChannel.Abort();
39             sender = proxy.ChannelFactory.CreateChannel();
40         }
41     }

 

posted @ 2013-04-12 10:02  RR幻影  Views(294)  Comments(0)    收藏  举报