static void Main(string[] args) { Unity.Initialize(); var r = new Router <ILogger, OnlineLogger, OnlineLogger>(); Connectivity.ForceConnectionStatus(ConnectionStatus.Offline); Console.WriteLine("Calling Online, will attend offline: "); r.Logger.Write("Used offline."); Connectivity.ForceConnectionStatus(ConnectionStatus.Online); Console.WriteLine("Calling Online, will attend online: "); r.Logger.Write("Used Online. Clap Clap Clap."); Console.ReadKey(); }
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext) { Console.WriteLine("It's been intercepted."); if (!Connectivity.IsConnected() && input.Target is IOnline) { Console.WriteLine("It's been canceled."); var offline = ((input.Target as IOnline).Offline); if (offline == null) { throw new Exception("Online class did not initialized Offline Dispatcher."); } var offlineResult = input.MethodBase.Invoke(offline, this.GetObjects(input.Inputs)); return(input.CreateMethodReturn(offlineResult, this.GetObjects(input.Inputs))); } return(getNext()(input, getNext)); }