diff --git a/sample/PrismSample.Android/MainApplication.cs b/sample/PrismSample.Android/MainApplication.cs index d3a4f8b..1344b42 100644 --- a/sample/PrismSample.Android/MainApplication.cs +++ b/sample/PrismSample.Android/MainApplication.cs @@ -20,7 +20,7 @@ public MainApplication(IntPtr javaReference, JniHandleOwnership transfer) public override void OnCreate() { base.OnCreate(); - AndroidShinyHost.Init(this, new Startup()); + this.ShinyOnCreate(new Startup()); } } } \ No newline at end of file diff --git a/sample/PrismSample.Android/PrismSample.Android.csproj b/sample/PrismSample.Android/PrismSample.Android.csproj index 19004d0..6b46bbf 100644 --- a/sample/PrismSample.Android/PrismSample.Android.csproj +++ b/sample/PrismSample.Android/PrismSample.Android.csproj @@ -16,7 +16,7 @@ Resources Assets false - v9.0 + v10.0 true true Xamarin.Android.Net.AndroidClientHandler @@ -53,7 +53,7 @@ - + diff --git a/sample/PrismSample.Android/Properties/AndroidManifest.xml b/sample/PrismSample.Android/Properties/AndroidManifest.xml index 6224fb4..b281ba2 100644 --- a/sample/PrismSample.Android/Properties/AndroidManifest.xml +++ b/sample/PrismSample.Android/Properties/AndroidManifest.xml @@ -1,6 +1,6 @@ - + - - - - + + + + \ No newline at end of file diff --git a/sample/PrismSample.Android/Resources/layout/Tabbar.xml b/sample/PrismSample.Android/Resources/layout/Tabbar.xml index ad1f87d..c78ab91 100644 --- a/sample/PrismSample.Android/Resources/layout/Tabbar.xml +++ b/sample/PrismSample.Android/Resources/layout/Tabbar.xml @@ -1,5 +1,5 @@ - + app:tabMode="fixed" /> \ No newline at end of file diff --git a/sample/PrismSample.Android/Resources/layout/Toolbar.xml b/sample/PrismSample.Android/Resources/layout/Toolbar.xml index aabd0a3..c2a56fd 100644 --- a/sample/PrismSample.Android/Resources/layout/Toolbar.xml +++ b/sample/PrismSample.Android/Resources/layout/Toolbar.xml @@ -1,4 +1,5 @@ - + - diff --git a/sample/PrismSample.Android/SplashActivity.cs b/sample/PrismSample.Android/SplashActivity.cs index fd1c9d0..358a817 100644 --- a/sample/PrismSample.Android/SplashActivity.cs +++ b/sample/PrismSample.Android/SplashActivity.cs @@ -1,8 +1,8 @@ using Android.App; using Android.OS; -using Android.Support.V7.App; using Android.Content; using Android.Util; +using AndroidX.AppCompat.App; namespace PrismSample.Droid { diff --git a/sample/PrismSample.UWP/App.xaml.cs b/sample/PrismSample.UWP/App.xaml.cs index eb65c33..9f4ec22 100644 --- a/sample/PrismSample.UWP/App.xaml.cs +++ b/sample/PrismSample.UWP/App.xaml.cs @@ -14,6 +14,8 @@ using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; +using Shiny; +using PrismSample.Shiny; namespace PrismSample.UWP { @@ -30,6 +32,7 @@ public App() { this.InitializeComponent(); this.Suspending += OnSuspending; + this.ShinyInit(new Startup()); } /// @@ -39,13 +42,9 @@ public App() /// Details about the launch request and process. protected override void OnLaunched(LaunchActivatedEventArgs e) { - - - Frame rootFrame = Window.Current.Content as Frame; - // Do not repeat app initialization when the Window already has content, // just ensure that the window is active - if (rootFrame == null) + if (!(Window.Current.Content is Frame rootFrame)) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); diff --git a/sample/PrismSample.UWP/PrismSample.UWP.csproj b/sample/PrismSample.UWP/PrismSample.UWP.csproj index 5bea7b0..0c87de5 100644 --- a/sample/PrismSample.UWP/PrismSample.UWP.csproj +++ b/sample/PrismSample.UWP/PrismSample.UWP.csproj @@ -143,10 +143,26 @@ - + + + {940ca2d8-b9a8-499a-9ed3-ecee9758073f} + Prism.Container.Extensions + + + {3a82a96a-f3fc-4244-87c3-28706494f614} + Prism.DryIoc.Extensions + + + {771a0fd7-7877-4ab7-8528-7fb07054393d} + Prism.Forms.Extended + + + {fd30086e-fa39-408e-935f-8921b454d282} + Shiny.Prism + {0C2D6820-FA64-4050-9546-BF034329D363} PrismSample diff --git a/sample/PrismSample.iOS/AppDelegate.cs b/sample/PrismSample.iOS/AppDelegate.cs index 323e911..02cd507 100644 --- a/sample/PrismSample.iOS/AppDelegate.cs +++ b/sample/PrismSample.iOS/AppDelegate.cs @@ -28,7 +28,7 @@ public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsAppli // public override bool FinishedLaunching(UIApplication app, NSDictionary options) { - iOSShinyHost.Init(new Startup()); + this.ShinyFinishedLaunching(new Startup()); global::Xamarin.Forms.Forms.Init(); LoadApplication(new App()); diff --git a/sample/PrismSample.iOS/PrismSample.iOS.csproj b/sample/PrismSample.iOS/PrismSample.iOS.csproj index 9e52f21..1780b5b 100644 --- a/sample/PrismSample.iOS/PrismSample.iOS.csproj +++ b/sample/PrismSample.iOS/PrismSample.iOS.csproj @@ -125,7 +125,7 @@ - + diff --git a/sample/PrismSample/PrismSample.csproj b/sample/PrismSample/PrismSample.csproj index e6ded96..1f63c23 100644 --- a/sample/PrismSample/PrismSample.csproj +++ b/sample/PrismSample/PrismSample.csproj @@ -8,7 +8,7 @@ - + diff --git a/sample/PrismSample/Shiny/Startup.cs b/sample/PrismSample/Shiny/Startup.cs index 2f09bcb..23d17fd 100644 --- a/sample/PrismSample/Shiny/Startup.cs +++ b/sample/PrismSample/Shiny/Startup.cs @@ -1,15 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; +using Shiny; using Shiny.Prism; -using Shiny.Power; namespace PrismSample.Shiny { public class Startup : PrismStartup { - protected override void ConfigureServices(IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services, IPlatform platform) { // Register Stuff } diff --git a/src/Prism.Container.Extensions/Prism.Container.Extensions.csproj b/src/Prism.Container.Extensions/Prism.Container.Extensions.csproj index aad6d60..99cec30 100644 --- a/src/Prism.Container.Extensions/Prism.Container.Extensions.csproj +++ b/src/Prism.Container.Extensions/Prism.Container.Extensions.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/Prism.DryIoc.Extensions/Prism.DryIoc.Extensions.csproj b/src/Prism.DryIoc.Extensions/Prism.DryIoc.Extensions.csproj index db2f50a..8e432e5 100644 --- a/src/Prism.DryIoc.Extensions/Prism.DryIoc.Extensions.csproj +++ b/src/Prism.DryIoc.Extensions/Prism.DryIoc.Extensions.csproj @@ -18,7 +18,7 @@ - + diff --git a/src/Prism.Microsoft.DependencyInjection.Extensions/Prism.Microsoft.DependencyInjection.Extensions.csproj b/src/Prism.Microsoft.DependencyInjection.Extensions/Prism.Microsoft.DependencyInjection.Extensions.csproj index c9338a1..247b053 100644 --- a/src/Prism.Microsoft.DependencyInjection.Extensions/Prism.Microsoft.DependencyInjection.Extensions.csproj +++ b/src/Prism.Microsoft.DependencyInjection.Extensions/Prism.Microsoft.DependencyInjection.Extensions.csproj @@ -14,7 +14,7 @@ - + diff --git a/src/Prism.Unity.Extensions/Prism.Unity.Extensions.csproj b/src/Prism.Unity.Extensions/Prism.Unity.Extensions.csproj index 089cc73..e64ee93 100644 --- a/src/Prism.Unity.Extensions/Prism.Unity.Extensions.csproj +++ b/src/Prism.Unity.Extensions/Prism.Unity.Extensions.csproj @@ -18,7 +18,7 @@ - + diff --git a/src/Shiny.Prism/PrismStartup.cs b/src/Shiny.Prism/PrismStartup.cs index 67b7f6b..fece7db 100644 --- a/src/Shiny.Prism/PrismStartup.cs +++ b/src/Shiny.Prism/PrismStartup.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using Prism.Container.Extensions.Internals; using Prism.Ioc; using Prism.Modularity; @@ -19,26 +20,30 @@ protected PrismStartup(IContainerExtension container) WithContainer(container); } - protected virtual void ConfigureApp(IServiceProvider provider) { } + protected virtual void ConfigureLogging(ILoggingBuilder builder, IPlatform platform) { } - protected abstract void ConfigureServices(IServiceCollection services); + protected abstract void ConfigureServices(IServiceCollection services, IPlatform platform); - void IShinyStartup.ConfigureServices(IServiceCollection services) + protected virtual void RegisterServices(IContainerRegistry containerRegistry) { } + + void IShinyStartup.ConfigureLogging(ILoggingBuilder builder, IPlatform platform) => + ConfigureLogging(builder, platform); + + void IShinyStartup.ConfigureServices(IServiceCollection services, IPlatform platform) { - ConfigureServices(services); + ConfigureServices(services, platform); services.RegisterPrismCoreServices(); services.Remove(services.First(x => x.ServiceType == typeof(IModuleInitializer))); services.AddSingleton(); } - void IShinyStartup.ConfigureApp(IServiceProvider provider) => ConfigureApp(provider); - IServiceProvider IShinyStartup.CreateServiceProvider(IServiceCollection services) { var container = ContainerLocationHelper.LocateContainer(CreateContainerExtension()) ?? throw new NullReferenceException("Call PrismContainerExtension.Init() prior to initializing PrismApplication"); var sp = container.CreateServiceProvider(services); + RegisterServices(container); var moduleCatalog = container.Resolve(); ConfigureModuleCatalog(moduleCatalog); @@ -60,29 +65,10 @@ protected virtual IContainerExtension CreateContainerExtension() public IShinyStartup WithContainer(IContainerExtension container) { ContainerLocator.SetContainerExtension(() => container); + var _ = ContainerLocator.Container; return this; } protected virtual void ConfigureModuleCatalog(IModuleCatalog moduleCatalog) { } } - - //public abstract class PrismStartupTask : IShinyStartupTask - //{ - // async void IShinyStartupTask.Start() - // { - // try - // { - // Start(); - // await StartAsync(); - // } - // catch (Exception ex) - // { - // Log.Write(ex); - // } - // } - - // protected virtual void Start() { } - - // protected virtual Task StartAsync() => Task.CompletedTask; - //} } diff --git a/src/Shiny.Prism/Shiny.Prism.csproj b/src/Shiny.Prism/Shiny.Prism.csproj index cdf9d52..0103446 100644 --- a/src/Shiny.Prism/Shiny.Prism.csproj +++ b/src/Shiny.Prism/Shiny.Prism.csproj @@ -12,7 +12,7 @@ - + diff --git a/tests/Prism.Container.Extensions.Shared.Tests/Tests/CommonAspNetServiceTests.cs b/tests/Prism.Container.Extensions.Shared.Tests/Tests/CommonAspNetServiceTests.cs index ad552de..1920879 100644 --- a/tests/Prism.Container.Extensions.Shared.Tests/Tests/CommonAspNetServiceTests.cs +++ b/tests/Prism.Container.Extensions.Shared.Tests/Tests/CommonAspNetServiceTests.cs @@ -7,6 +7,7 @@ using Xunit; using Prism.Ioc; using System.Net.Http; +using Microsoft.Extensions.Logging; #if DRYIOC using Prism.DryIoc; #elif UNITY @@ -131,6 +132,24 @@ public void ResolvesHttpClientWithHttpClientFactory() Assert.NotNull(client); } + [Fact] + public void RegistersOpenGenerics() + { + PrismContainerExtension.Current.RegisterServices(s => + { + s.AddLogging(b => b.SetMinimumLevel(LogLevel.Warning)); + }); + + ILogger logger = null; + var ex = Record.Exception(() => + { + logger = PrismContainerExtension.Current.Resolve>(); + }); + + Assert.Null(ex); + Assert.NotNull(logger); + } + private void ConfigureServices() { var services = new ServiceCollection(); diff --git a/tests/Prism.DryIoc.Extensions.Tests/Prism.DryIoc.Extensions.Tests.csproj b/tests/Prism.DryIoc.Extensions.Tests/Prism.DryIoc.Extensions.Tests.csproj index f64d610..64002d3 100644 --- a/tests/Prism.DryIoc.Extensions.Tests/Prism.DryIoc.Extensions.Tests.csproj +++ b/tests/Prism.DryIoc.Extensions.Tests/Prism.DryIoc.Extensions.Tests.csproj @@ -7,10 +7,10 @@ - - - - + + + + diff --git a/tests/Prism.DryIoc.Forms.Extended.Tests/Prism.DryIoc.Forms.Extended.Tests.csproj b/tests/Prism.DryIoc.Forms.Extended.Tests/Prism.DryIoc.Forms.Extended.Tests.csproj index d413045..be8416e 100644 --- a/tests/Prism.DryIoc.Forms.Extended.Tests/Prism.DryIoc.Forms.Extended.Tests.csproj +++ b/tests/Prism.DryIoc.Forms.Extended.Tests/Prism.DryIoc.Forms.Extended.Tests.csproj @@ -10,7 +10,7 @@ - + diff --git a/tests/Prism.Microsoft.DependencyInjection.Extensions.Forms.Tests/Prism.Microsoft.DependencyInjection.Forms.Extended.Tests.csproj b/tests/Prism.Microsoft.DependencyInjection.Extensions.Forms.Tests/Prism.Microsoft.DependencyInjection.Forms.Extended.Tests.csproj index 5eaeb09..0a9fc1e 100644 --- a/tests/Prism.Microsoft.DependencyInjection.Extensions.Forms.Tests/Prism.Microsoft.DependencyInjection.Forms.Extended.Tests.csproj +++ b/tests/Prism.Microsoft.DependencyInjection.Extensions.Forms.Tests/Prism.Microsoft.DependencyInjection.Forms.Extended.Tests.csproj @@ -9,7 +9,7 @@ - + diff --git a/tests/Prism.Microsoft.DependencyInjection.Extensions.Tests/Prism.Microsoft.DependencyInjection.Extensions.Tests.csproj b/tests/Prism.Microsoft.DependencyInjection.Extensions.Tests/Prism.Microsoft.DependencyInjection.Extensions.Tests.csproj index 5a0d6a8..5d2fc20 100644 --- a/tests/Prism.Microsoft.DependencyInjection.Extensions.Tests/Prism.Microsoft.DependencyInjection.Extensions.Tests.csproj +++ b/tests/Prism.Microsoft.DependencyInjection.Extensions.Tests/Prism.Microsoft.DependencyInjection.Extensions.Tests.csproj @@ -7,9 +7,9 @@ - - - + + + diff --git a/tests/Prism.Unity.Extensions.Tests/Prism.Unity.Extensions.Tests.csproj b/tests/Prism.Unity.Extensions.Tests/Prism.Unity.Extensions.Tests.csproj index eb7d392..fd7fbd7 100644 --- a/tests/Prism.Unity.Extensions.Tests/Prism.Unity.Extensions.Tests.csproj +++ b/tests/Prism.Unity.Extensions.Tests/Prism.Unity.Extensions.Tests.csproj @@ -7,10 +7,10 @@ - - - - + + + + diff --git a/tests/Prism.Unity.Forms.Extended.Tests/Prism.Unity.Forms.Extended.Tests.csproj b/tests/Prism.Unity.Forms.Extended.Tests/Prism.Unity.Forms.Extended.Tests.csproj index 9199799..dbeb771 100644 --- a/tests/Prism.Unity.Forms.Extended.Tests/Prism.Unity.Forms.Extended.Tests.csproj +++ b/tests/Prism.Unity.Forms.Extended.Tests/Prism.Unity.Forms.Extended.Tests.csproj @@ -8,7 +8,7 @@ - + diff --git a/tests/Shiny.Prism.Tests/Mocks/MockStartup.cs b/tests/Shiny.Prism.Tests/Mocks/MockStartup.cs index a1435d1..94f0d32 100644 --- a/tests/Shiny.Prism.Tests/Mocks/MockStartup.cs +++ b/tests/Shiny.Prism.Tests/Mocks/MockStartup.cs @@ -1,19 +1,15 @@ using System; -using System.Collections.Generic; -using System.Text; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Prism.DryIoc; using Prism.Ioc; -//using Shiny.Beacons; -using Shiny.BluetoothLE; -using Shiny.Locations; using Shiny.Prism.Mocks.Delegates; -using Shiny.Logging; using Xunit.Abstractions; namespace Shiny.Prism.Mocks { - public class MockStartup : PrismStartup, ILogger + public class MockStartup : PrismStartup, ILoggerProvider { private ITestOutputHelper _testOutputHelper { get; } @@ -28,11 +24,15 @@ public MockStartup(ITestOutputHelper testOutputHelper, bool setContainer = true) } } - protected override void ConfigureServices(IServiceCollection services) + protected override void ConfigureLogging(ILoggingBuilder builder, IPlatform platform) { - Log.Loggers.Clear(); - Log.AddLogger(this); + base.ConfigureLogging(builder, platform); + builder.ClearProviders(); + builder.AddProvider(this); + } + protected override void ConfigureServices(IServiceCollection services, IPlatform platform) + { //services.UseBeacons(); services.UseGps(); services.UseGeofencing(); @@ -66,5 +66,47 @@ private void WriteParams((string Key, string Value)[] parameters) _testOutputHelper.WriteLine($"{Key}: {Value}"); } } + + ILogger ILoggerProvider.CreateLogger(string categoryName) + { + return new Logger(categoryName, _testOutputHelper); + } + + void IDisposable.Dispose() + { + } + + class Logger : ILogger + { + private string _name { get; } + private ITestOutputHelper _output { get; } + + public Logger(string name, ITestOutputHelper output) + { + _name = name; + _output = output; + } + + public IDisposable BeginScope(TState state) + { + return new EmptyDisposable(); + } + + public bool IsEnabled(LogLevel logLevel) + { + return true; + } + + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) + { + var logEntry = new LogEntry(logLevel, _name, eventId, state, exception, formatter); + _output.WriteLine(logEntry.ToString()); + } + + class EmptyDisposable : IDisposable + { + public void Dispose() { } + } + } } } diff --git a/tests/Shiny.Prism.Tests/Mocks/ShinyPrismTestHost.cs b/tests/Shiny.Prism.Tests/Mocks/ShinyPrismTestHost.cs index 71d9345..37d9d83 100644 --- a/tests/Shiny.Prism.Tests/Mocks/ShinyPrismTestHost.cs +++ b/tests/Shiny.Prism.Tests/Mocks/ShinyPrismTestHost.cs @@ -1,8 +1,7 @@ using System; -using System.Collections.Generic; -using System.Text; +using System.Reactive.Subjects; using Microsoft.Extensions.DependencyInjection; -using Shiny.IO; +using Shiny.Infrastructure; using Shiny.Jobs; using Shiny.Net; using Shiny.Power; @@ -16,22 +15,31 @@ namespace Shiny.Prism.Mocks { - class ShinyPrismTestHost : ShinyHost + class ShinyPrismTestHost : TestPlatform { + private readonly Action _platformBuild; + + private ShinyPrismTestHost(Action platformBuild) + { + _platformBuild = platformBuild; + } + public static void Init(ITestOutputHelper testOutputHelper) => Init(new MockStartup(testOutputHelper)); public static void Init(IShinyStartup startup = null, Action platformBuild = null) { - InitPlatform(startup, services => - { - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - platformBuild?.Invoke(services); - }); + ShinyHost.Init(new ShinyPrismTestHost(platformBuild), startup); + } + + public override void Register(IServiceCollection services) + { + base.Register(services); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + _platformBuild?.Invoke(services); } } } diff --git a/tests/Shiny.Prism.Tests/Shiny.Prism.Tests.csproj b/tests/Shiny.Prism.Tests/Shiny.Prism.Tests.csproj index 026a2ce..aab2d07 100644 --- a/tests/Shiny.Prism.Tests/Shiny.Prism.Tests.csproj +++ b/tests/Shiny.Prism.Tests/Shiny.Prism.Tests.csproj @@ -9,7 +9,7 @@ - + all diff --git a/tests/Shiny.Prism.Tests/Tests/PrismStartupTests.cs b/tests/Shiny.Prism.Tests/Tests/PrismStartupTests.cs index 816083f..bc92e8a 100644 --- a/tests/Shiny.Prism.Tests/Tests/PrismStartupTests.cs +++ b/tests/Shiny.Prism.Tests/Tests/PrismStartupTests.cs @@ -1,13 +1,12 @@ using System; +using System.Linq; using Prism.DryIoc; using Prism.Ioc; -using Shiny.IO; using Shiny.Jobs; using Shiny.Net; using Shiny.Power; using Shiny.Prism.Mocks; using Shiny.Settings; -using Shiny.Testing; using Shiny.Testing.Jobs; using Shiny.Testing.Net; using Shiny.Testing.Power; @@ -36,16 +35,21 @@ public void DoesNotThrowExceptionOnStartup() } [Theory] + [InlineData(typeof(IPlatform), typeof(ShinyPrismTestHost))] [InlineData(typeof(IJobManager), typeof(TestJobManager))] [InlineData(typeof(IConnectivity), typeof(TestConnectivity))] [InlineData(typeof(IPowerManager), typeof(TestPowerManager))] - [InlineData(typeof(IFileSystem), typeof(FileSystemImpl))] [InlineData(typeof(ISettings), typeof(TestSettings))] - [InlineData(typeof(IEnvironment), typeof(TestEnvironment))] - //[InlineData(typeof(IBleAdapterDelegate), typeof(MockBleAdapterDelegate))] public void ExpectedTypesAreRegisteredAndResolve(Type serviceType, Type implementingType) { ShinyPrismTestHost.Init(_testOutputHelper); + var types = ContainerLocator.Container + .GetContainer() + .GetServiceRegistrations() + .Where(x => x.ServiceType.Assembly.GetName().Name == "Shiny.Core"); + foreach (var type in types) + _testOutputHelper.WriteLine($"Found: {type.ServiceType.FullName} - {type.ImplementationType?.FullName}"); + Assert.True(PrismContainerExtension.Current.IsRegistered(serviceType)); var fromShiny = ShinyHost.Container.GetService(serviceType); @@ -59,7 +63,7 @@ public void PrismStartupLocatesContainerExtension() var ex = Record.Exception(() => ShinyPrismTestHost.Init(new MockStartup(_testOutputHelper, false))); Assert.Null(ex); - Assert.NotNull(PrismContainerExtension.Current.Resolve()); + Assert.NotNull(PrismContainerExtension.Current.Resolve()); } } }