diff --git a/src/Caliburn.Micro.Core/EventAggregator.cs b/src/Caliburn.Micro.Core/EventAggregator.cs index 6657e877..01bde8d5 100644 --- a/src/Caliburn.Micro.Core/EventAggregator.cs +++ b/src/Caliburn.Micro.Core/EventAggregator.cs @@ -10,11 +10,6 @@ namespace Caliburn.Micro /// public class EventAggregator : IEventAggregator { - /// - /// Processing of handler results on publication thread. - /// - public static Action HandlerResultProcessing = (target, result) => { }; - private readonly List _handlers = new List(); /// diff --git a/src/Caliburn.Micro.Platform/Platforms/Android/CaliburnApplication.cs b/src/Caliburn.Micro.Platform/Platforms/Android/CaliburnApplication.cs index 9c4cca8b..3b80222e 100644 --- a/src/Caliburn.Micro.Platform/Platforms/Android/CaliburnApplication.cs +++ b/src/Caliburn.Micro.Platform/Platforms/Android/CaliburnApplication.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Reflection; -using System.Threading.Tasks; using Android.App; using Android.Runtime; @@ -45,25 +44,6 @@ protected virtual void StartDesignTime() /// B protected virtual void StartRuntime() { - EventAggregator.HandlerResultProcessing = (target, result) => - { - var task = result as Task; - if (task != null) - { - result = new IResult[] { task.AsResult() }; - } - - var coroutine = result as IEnumerable; - if (coroutine != null) - { - var viewAware = target as IViewAware; - var view = viewAware != null ? viewAware.GetView() : null; - var context = new CoroutineExecutionContext { Target = target, View = view }; - - Coroutine.BeginExecute(coroutine.GetEnumerator(), context); - } - }; - AssemblySourceCache.Install(); AssemblySource.Instance.AddRange(SelectAssemblies()); @@ -152,4 +132,4 @@ protected virtual void BuildUp(object instance) { } } -} \ No newline at end of file +} diff --git a/src/Caliburn.Micro.Platform/Platforms/UWP/CaliburnApplication.cs b/src/Caliburn.Micro.Platform/Platforms/UWP/CaliburnApplication.cs index 2ec94d30..42ce6445 100644 --- a/src/Caliburn.Micro.Platform/Platforms/UWP/CaliburnApplication.cs +++ b/src/Caliburn.Micro.Platform/Platforms/UWP/CaliburnApplication.cs @@ -1,16 +1,18 @@ -namespace Caliburn.Micro { - using System; - using System.Collections.Generic; - using System.Linq; - using System.Reflection; - using Windows.ApplicationModel; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Controls; - +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using Windows.ApplicationModel; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; + +namespace Caliburn.Micro +{ /// /// Encapsulates the app and its available services. /// - public abstract class CaliburnApplication : Application { + public abstract class CaliburnApplication : Application + { private bool isInitialized; /// @@ -21,7 +23,8 @@ public abstract class CaliburnApplication : Application { /// /// Called by the bootstrapper's constructor at design time to start the framework. /// - protected virtual void StartDesignTime() { + protected virtual void StartDesignTime() + { AssemblySource.Instance.Clear(); AssemblySource.Instance.AddRange(SelectAssemblies()); @@ -34,23 +37,8 @@ protected virtual void StartDesignTime() { /// /// Called by the bootstrapper's constructor at runtime to start the framework. /// - protected virtual void StartRuntime() { - EventAggregator.HandlerResultProcessing = (target, result) => { - var task = result as System.Threading.Tasks.Task; - if (task != null) { - result = new IResult[] {task.AsResult()}; - } - - var coroutine = result as IEnumerable; - if (coroutine != null) { - var viewAware = target as IViewAware; - var view = viewAware != null ? viewAware.GetView() : null; - var context = new CoroutineExecutionContext {Target = target, View = view}; - - Coroutine.BeginExecute(coroutine.GetEnumerator(), context); - } - }; - + protected virtual void StartRuntime() + { AssemblySourceCache.Install(); AssemblySource.Instance.AddRange(SelectAssemblies()); @@ -65,8 +53,10 @@ protected virtual void StartRuntime() { /// /// Start the framework. /// - protected void Initialize() { - if (isInitialized) { + protected void Initialize() + { + if (isInitialized) + { return; } @@ -88,17 +78,21 @@ protected void Initialize() { AssemblySource.Instance.Refresh(); - if (Execute.InDesignMode) { - try { + if (Execute.InDesignMode) + { + try + { StartDesignTime(); } - catch { + catch + { //if something fails at design-time, there's really nothing we can do... isInitialized = false; throw; } } - else { + else + { StartRuntime(); } } @@ -107,7 +101,8 @@ protected void Initialize() { /// Invoked when the application creates a window. /// /// Event data for the event. - protected override void OnWindowCreated(WindowCreatedEventArgs args) { + protected override void OnWindowCreated(WindowCreatedEventArgs args) + { base.OnWindowCreated(args); // Because dispatchers are tied to windows Execute will fail in @@ -120,7 +115,8 @@ protected override void OnWindowCreated(WindowCreatedEventArgs args) { /// /// Provides an opportunity to hook into the application object. /// - protected virtual void PrepareApplication() { + protected virtual void PrepareApplication() + { Resuming += OnResuming; Suspending += OnSuspending; UnhandledException += OnUnhandledException; @@ -129,14 +125,16 @@ protected virtual void PrepareApplication() { /// /// Override to configure the framework and setup your IoC container. /// - protected virtual void Configure() { + protected virtual void Configure() + { } /// /// Override to tell the framework where to find assemblies to inspect for views, etc. /// /// A list of assemblies to inspect. - protected virtual IEnumerable SelectAssemblies() { + protected virtual IEnumerable SelectAssemblies() + { return new[] {GetType().GetTypeInfo().Assembly}; } @@ -146,7 +144,8 @@ protected virtual IEnumerable SelectAssemblies() { /// The service to locate. /// The key to locate. /// The located service. - protected virtual object GetInstance(Type service, string key) { + protected virtual object GetInstance(Type service, string key) + { return System.Activator.CreateInstance(service); } @@ -155,7 +154,8 @@ protected virtual object GetInstance(Type service, string key) { /// /// The service to locate. /// The located services. - protected virtual IEnumerable GetAllInstances(Type service) { + protected virtual IEnumerable GetAllInstances(Type service) + { return new[] {System.Activator.CreateInstance(service)}; } @@ -163,7 +163,8 @@ protected virtual IEnumerable GetAllInstances(Type service) { /// Override this to provide an IoC specific implementation. /// /// The instance to perform injection on. - protected virtual void BuildUp(object instance) { + protected virtual void BuildUp(object instance) + { } /// @@ -171,7 +172,8 @@ protected virtual void BuildUp(object instance) { /// /// The sender. /// The event args. - protected virtual void OnResuming(object sender, object e) { + protected virtual void OnResuming(object sender, object e) + { } /// @@ -179,7 +181,8 @@ protected virtual void OnResuming(object sender, object e) { /// /// The sender. /// The event args. - protected virtual void OnSuspending(object sender, SuspendingEventArgs e) { + protected virtual void OnSuspending(object sender, SuspendingEventArgs e) + { } /// @@ -187,21 +190,24 @@ protected virtual void OnSuspending(object sender, SuspendingEventArgs e) { /// /// The sender. /// The event args. - protected virtual void OnUnhandledException(object sender, UnhandledExceptionEventArgs e) { + protected virtual void OnUnhandledException(object sender, UnhandledExceptionEventArgs e) + { } /// /// Creates the root frame used by the application. /// /// The frame. - protected virtual Frame CreateApplicationFrame() { + protected virtual Frame CreateApplicationFrame() + { return new Frame(); } /// /// Allows you to trigger the creation of the RootFrame from Configure if necessary. /// - protected virtual void PrepareViewFirst() { + protected virtual void PrepareViewFirst() + { if (RootFrame != null) return; @@ -213,7 +219,8 @@ protected virtual void PrepareViewFirst() { /// Override this to register a navigation service. /// /// The root frame of the application. - protected virtual void PrepareViewFirst(Frame rootFrame) { + protected virtual void PrepareViewFirst(Frame rootFrame) + { } /// @@ -221,7 +228,8 @@ protected virtual void PrepareViewFirst(Frame rootFrame) { /// /// The view type to navigate to. /// The object parameter to pass to the target. - protected void DisplayRootView(Type viewType, object paramter = null) { + protected void DisplayRootView(Type viewType, object paramter = null) + { Initialize(); PrepareViewFirst(); @@ -240,15 +248,17 @@ protected void DisplayRootView(Type viewType, object paramter = null) { /// /// The view type to navigate to. /// The object parameter to pass to the target. - protected void DisplayRootView(object parameter = null) { - DisplayRootView(typeof (T), parameter); + protected void DisplayRootView(object parameter = null) + { + DisplayRootView(typeof(T), parameter); } /// /// Locates the view model, locates the associate view, binds them and shows it as the root view. /// /// The view model type. - protected void DisplayRootViewFor(Type viewModelType) { + protected void DisplayRootViewFor(Type viewModelType) + { Initialize(); var viewModel = IoC.GetInstance(viewModelType, null); @@ -268,8 +278,9 @@ protected void DisplayRootViewFor(Type viewModelType) { /// Locates the view model, locates the associate view, binds them and shows it as the root view. /// /// The view model type. - protected void DisplayRootViewFor() { - DisplayRootViewFor(typeof (T)); + protected void DisplayRootViewFor() + { + DisplayRootViewFor(typeof(T)); } } } diff --git a/src/Caliburn.Micro.Platform/Platforms/WPF/Bootstrapper.cs b/src/Caliburn.Micro.Platform/Platforms/WPF/Bootstrapper.cs index a9c8a1f3..f5bdbd6f 100644 --- a/src/Caliburn.Micro.Platform/Platforms/WPF/Bootstrapper.cs +++ b/src/Caliburn.Micro.Platform/Platforms/WPF/Bootstrapper.cs @@ -1,37 +1,41 @@ -namespace Caliburn.Micro { - using System; - using System.Collections.Generic; - using System.Linq; - using System.Reflection; - using System.Windows; - using System.Windows.Threading; - - +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Windows; +using System.Windows.Threading; + +namespace Caliburn.Micro +{ /// /// Inherit from this class in order to customize the configuration of the framework. /// - public abstract class BootstrapperBase { + public abstract class BootstrapperBase + { readonly bool useApplication; bool isInitialized; - /// - /// The application. - /// - protected Application Application { get; set; } - /// /// Creates an instance of the bootstrapper. /// /// Set this to false when hosting Caliburn.Micro inside and Office or WinForms application. The default is true. - protected BootstrapperBase(bool useApplication = true) { + protected BootstrapperBase(bool useApplication = true) + { this.useApplication = useApplication; } + /// + /// The application. + /// + protected Application Application { get; set; } + /// /// Initialize the framework. /// - public void Initialize() { - if(isInitialized) { + public void Initialize() + { + if (isInitialized) + { return; } @@ -53,16 +57,21 @@ public void Initialize() { AssemblySource.Instance.Refresh(); - if(Execute.InDesignMode) { - try { + if (Execute.InDesignMode) + { + try + { StartDesignTime(); - }catch { + } + catch + { //if something fails at design-time, there's really nothing we can do... isInitialized = false; throw; } } - else { + else + { StartRuntime(); } } @@ -70,7 +79,8 @@ public void Initialize() { /// /// Called by the bootstrapper's constructor at design time to start the framework. /// - protected virtual void StartDesignTime() { + protected virtual void StartDesignTime() + { AssemblySource.Instance.Clear(); AssemblySource.Instance.AddRange(SelectAssemblies()); @@ -83,27 +93,13 @@ protected virtual void StartDesignTime() { /// /// Called by the bootstrapper's constructor at runtime to start the framework. /// - protected virtual void StartRuntime() { - EventAggregator.HandlerResultProcessing = (target, result) => { - var task = result as System.Threading.Tasks.Task; - if (task != null) { - result = new IResult[] {task.AsResult()}; - } - - var coroutine = result as IEnumerable; - if (coroutine != null) { - var viewAware = target as IViewAware; - var view = viewAware != null ? viewAware.GetView() : null; - var context = new CoroutineExecutionContext { Target = target, View = view }; - - Coroutine.BeginExecute(coroutine.GetEnumerator(), context); - } - }; - + protected virtual void StartRuntime() + { AssemblySourceCache.Install(); AssemblySource.Instance.AddRange(SelectAssemblies()); - if (useApplication) { + if (useApplication) + { Application = Application.Current; PrepareApplication(); } @@ -117,7 +113,8 @@ protected virtual void StartRuntime() { /// /// Provides an opportunity to hook into the application object. /// - protected virtual void PrepareApplication() { + protected virtual void PrepareApplication() + { Application.Startup += OnStartup; Application.DispatcherUnhandledException += OnUnhandledException; @@ -128,14 +125,17 @@ protected virtual void PrepareApplication() { /// /// Override to configure the framework and setup your IoC container. /// - protected virtual void Configure() { } + protected virtual void Configure() + { + } /// /// Override to tell the framework where to find assemblies to inspect for views, etc. /// /// A list of assemblies to inspect. - protected virtual IEnumerable SelectAssemblies() { - return new[] { GetType().Assembly }; + protected virtual IEnumerable SelectAssemblies() + { + return new[] {GetType().Assembly}; } /// @@ -144,8 +144,8 @@ protected virtual IEnumerable SelectAssemblies() { /// The service to locate. /// The key to locate. /// The located service. - protected virtual object GetInstance(Type service, string key) { - + protected virtual object GetInstance(Type service, string key) + { if (service == typeof(IWindowManager)) service = typeof(WindowManager); @@ -157,43 +157,53 @@ protected virtual object GetInstance(Type service, string key) { /// /// The service to locate. /// The located services. - protected virtual IEnumerable GetAllInstances(Type service) { - return new[] { Activator.CreateInstance(service) }; + protected virtual IEnumerable GetAllInstances(Type service) + { + return new[] {Activator.CreateInstance(service)}; } /// /// Override this to provide an IoC specific implementation. /// /// The instance to perform injection on. - protected virtual void BuildUp(object instance) { } + protected virtual void BuildUp(object instance) + { + } /// /// Override this to add custom behavior to execute after the application starts. /// /// The sender. /// The args. - protected virtual void OnStartup(object sender, StartupEventArgs e) { } + protected virtual void OnStartup(object sender, StartupEventArgs e) + { + } /// /// Override this to add custom behavior on exit. /// /// The sender. /// The event args. - protected virtual void OnExit(object sender, EventArgs e) { } + protected virtual void OnExit(object sender, EventArgs e) + { + } /// /// Override this to add custom behavior for unhandled exceptions. /// /// The sender. /// The event args. - protected virtual void OnUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { } - + protected virtual void OnUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) + { + } + /// /// Locates the view model, locates the associate view, binds them and shows it as the root view. /// /// The view model type. /// The optional window settings. - protected void DisplayRootViewFor(Type viewModelType, IDictionary settings = null) { + protected void DisplayRootViewFor(Type viewModelType, IDictionary settings = null) + { var windowManager = IoC.Get(); windowManager.ShowWindow(IoC.GetInstance(viewModelType, null), null, settings); } @@ -203,7 +213,8 @@ protected void DisplayRootViewFor(Type viewModelType, IDictionary /// The view model type. /// The optional window settings. - protected void DisplayRootViewFor(IDictionary settings = null) { + protected void DisplayRootViewFor(IDictionary settings = null) + { DisplayRootViewFor(typeof(TViewModel), settings); } } diff --git a/src/Caliburn.Micro.Platform/Platforms/iOS/CaliburnApplicationDelegate.cs b/src/Caliburn.Micro.Platform/Platforms/iOS/CaliburnApplicationDelegate.cs index 9c3d07c9..412b60dd 100644 --- a/src/Caliburn.Micro.Platform/Platforms/iOS/CaliburnApplicationDelegate.cs +++ b/src/Caliburn.Micro.Platform/Platforms/iOS/CaliburnApplicationDelegate.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Reflection; -using System.Threading.Tasks; using Foundation; using UIKit; @@ -12,21 +11,21 @@ namespace Caliburn.Micro /// public class CaliburnApplicationDelegate : UIApplicationDelegate { - private bool isInitialized; + private bool _isInitialized; /// /// Creates an instance of . /// - public CaliburnApplicationDelegate() { - + public CaliburnApplicationDelegate() + { } /// /// Creates an instance of . /// /// /// The handle for this class - public CaliburnApplicationDelegate(IntPtr handle) : base(handle) { - + public CaliburnApplicationDelegate(IntPtr handle) : base(handle) + { } /// @@ -36,7 +35,6 @@ public CaliburnApplicationDelegate(IntPtr handle) : base(handle) { public CaliburnApplicationDelegate(NSObjectFlag t) : base(t) { - } /// @@ -59,25 +57,6 @@ protected virtual void StartDesignTime() /// B protected virtual void StartRuntime() { - EventAggregator.HandlerResultProcessing = (target, result) => - { - var task = result as Task; - if (task != null) - { - result = new IResult[] { task.AsResult() }; - } - - var coroutine = result as IEnumerable; - if (coroutine != null) - { - var viewAware = target as IViewAware; - var view = viewAware != null ? viewAware.GetView() : null; - var context = new CoroutineExecutionContext { Target = target, View = view }; - - Coroutine.BeginExecute(coroutine.GetEnumerator(), context); - } - }; - AssemblySourceCache.Install(); AssemblySource.Instance.AddRange(SelectAssemblies()); @@ -92,17 +71,14 @@ protected virtual void StartRuntime() /// protected void Initialize() { - if (isInitialized) - { + if (_isInitialized) return; - } - isInitialized = true; + _isInitialized = true; PlatformProvider.Current = new IOSPlatformProvider(); if (Execute.InDesignMode) - { try { StartDesignTime(); @@ -110,14 +86,11 @@ protected void Initialize() catch { //if something fails at design-time, there's really nothing we can do... - isInitialized = false; + _isInitialized = false; throw; } - } else - { StartRuntime(); - } } /// @@ -133,7 +106,7 @@ protected virtual void Configure() /// A list of assemblies to inspect. protected virtual IEnumerable SelectAssemblies() { - return new[] { GetType().GetTypeInfo().Assembly }; + return new[] {GetType().GetTypeInfo().Assembly}; } /// @@ -154,7 +127,7 @@ protected virtual object GetInstance(Type service, string key) /// The located services. protected virtual IEnumerable GetAllInstances(Type service) { - return new[] { Activator.CreateInstance(service) }; + return new[] {Activator.CreateInstance(service)}; } /// @@ -165,4 +138,4 @@ protected virtual void BuildUp(object instance) { } } -} \ No newline at end of file +}