Example #1
0
        public IAppStartup GetAppStartup()
        {
            if (startup != null)
            {
                return(startup);
            }
            switch (configuration)
            {
            // Different implementations of startup
            case nameof(HybridAppStartup):
                startup = new HybridAppStartup();
                break;

            case nameof(WriteStackAppStartup):
                startup = new WriteStackAppStartup();
                break;

            case nameof(ReactiveAppStartup):
                startup = new ReactiveAppStartup();
                break;

            default: throw new Exception("Invalid configuration");
            }
            return(startup);
        }
Example #2
0
        public IAppStartup GetAppStartup()
        {
            if (startup != null)
            {
                return(startup);
            }
            switch (configuration)
            {
            case "hybrid":
                startup = new MockHybridAppStartup();
                break;

            case "reactive":
                startup = new MockReactiveAppStartup();
                break;

            default: throw new Exception("Invalid configuration");
            }
            return(startup);
        }
        public static IAppStartup AddNHibernate(
            this IAppStartup appStartup,
            Configuration configuration,
            Assembly mappingsAssembly,
            Type idUserTypeGenericType)
        {
            // todo: check args

            appStartup.GetContainerBuilder()
            .Register(c => BuildSessionFactory(configuration, mappingsAssembly, idUserTypeGenericType))
            .As <ISessionFactory>()
            .SingleInstance();

            appStartup.GetContainerBuilder()
            .Register(c => c.Resolve <ISessionFactory>().OpenSession())
            .As <ISession>()
            .InstancePerLifetimeScope();

            return(appStartup);
        }
Example #4
0
        public SplashViewModel(IParameterViewStackService parameterViewStackService, IAppStartup appStartup)
            : base(parameterViewStackService)
        {
            _appStartup = appStartup;
            Initialize  = ReactiveCommand.CreateFromObservable(ExecuteInitialize);
            Navigate    = ReactiveCommand.CreateFromObservable(ExecuteNavigate);

            var initializing =
                this.WhenAnyObservable(x => x.Initialize.IsExecuting)
                .StartWith(false);

            initializing
            .ToProperty(this, nameof(IsLoading), out _loading)
            .DisposeWith(Subscriptions);

            initializing
            .Zip(initializing.Skip(1), (first, second) => first && !second)
            .Where(x => x)
            .Select(x => Unit.Default)
            .InvokeCommand(Navigate);
        }
Example #5
0
 public void StartApp(IAppStartup app, IApplicationBuilder applicationBuilder)
 {
     Logger.LogInformation($"Starting app {app.Name}");
     try
     {
         var serviceCollection = new ServiceCollection();
         app.ConfigureServices(serviceCollection);
         var newAppBuilder = applicationBuilder.New();
         newAppBuilder.ApplicationServices = serviceCollection.BuildServiceProvider();
         app.Configure(newAppBuilder);
         Apps.Add(new AppEntry()
         {
             Startup         = app,
             RequestDelegate = newAppBuilder.Build()
         });
         Logger.LogInformation($"Started app {app.Name}");
     }
     catch (Exception e)
     {
         Logger.LogError(e, $"Could not start app {app.Name}");
     }
 }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SplashViewModel"/> class.
        /// </summary>
        /// <param name="popupViewStackService">The popup view stack service.</param>
        /// <param name="appStartup">The app startup.</param>
        public SplashViewModel(IPopupViewStackService popupViewStackService, IAppStartup appStartup)
            : base(popupViewStackService)
        {
            _appStartup = appStartup;
            Initialize  = ReactiveCommand.CreateFromObservable(ExecuteInitialize);
            Navigate    = ReactiveCommand.CreateFromObservable(ExecuteNavigate);

            var initializing =
                this.WhenAnyObservable(x => x.Initialize.IsExecuting)
                .StartWith(false);

            initializing
            .Zip(initializing.Skip(1), (first, second) => first && !second)
            .Where(x => x)
            .Select(_ => Unit.Default)
            .InvokeCommand(Navigate);

            _appStartup
            .WhenPropertyValueChanges(x => x.IsCompleted)
            .DistinctUntilChanged()
            .ToProperty(this, nameof(IsLoading), out _loading, scheduler: RxApp.MainThreadScheduler)
            .DisposeWith(Subscriptions);
        }
        public static IAppStartup AddCqrs(this IAppStartup appStartup, Assembly cqrsAssembly, Type commandHandlerDecoratorType)
        {
            // todo arg checks

            // command dispatching
            appStartup.GetContainerBuilder()
            .RegisterType <CommandDispatcher>()
            .As <ICommandDispatcher>()
            .InstancePerLifetimeScope();

            appStartup.GetContainerBuilder()
            .RegisterType <ValidatingCommandDispatcher>()
            .As <IValidatingCommandDispatcher>()
            .InstancePerLifetimeScope();

            appStartup.GetContainerBuilder()
            .RegisterType <AutofacCommandHandlerFactory>()
            .As <ICommandHandlerFactory>()
            .InstancePerLifetimeScope();

            // register API ICommandHandler decorator
            appStartup.GetContainerBuilder()
            .RegisterAssemblyTypes(cqrsAssembly)
            .Where(t => t.IsClosedTypeOf(typeof(ICommandHandler <>)))
            .As(t => t.GetInterfaces()
                .Where(x => x.IsClosedTypeOf(typeof(ICommandHandler <>)))
                .Select(x => new KeyedService("commandHandler", x)))
            .InstancePerLifetimeScope();

            appStartup.GetContainerBuilder()
            .RegisterGenericDecorator(
                commandHandlerDecoratorType,
                typeof(ICommandHandler <>),

                "commandHandler");

            // command validator source
            appStartup.GetContainerBuilder()
            .RegisterInstance(new CommandValidatorSource(cqrsAssembly))
            .As <ICommandValidatorSource>()
            .SingleInstance();

            // validators
            appStartup.GetContainerBuilder()
            .RegisterAssemblyTypes(cqrsAssembly)
            .Where(t => t.IsClosedTypeOf(typeof(AbstractValidator <>)))
            .AsSelf()
            .InstancePerLifetimeScope();

            // query handling
            appStartup.GetContainerBuilder()
            .RegisterType <QueryRunner>()
            .As <IQueryRunner>()
            .InstancePerLifetimeScope();

            appStartup.GetContainerBuilder()
            .RegisterType <ValidatingQueryRunner>()
            .As <IValidatingQueryRunner>()
            .InstancePerLifetimeScope();

            appStartup.GetContainerBuilder()
            .RegisterType <AutofacQueryHandlerFactory>()
            .As <IQueryHandlerFactory>()
            .InstancePerLifetimeScope();

            appStartup.GetContainerBuilder()
            .RegisterAssemblyTypes(cqrsAssembly)
            .Where(t => t.IsClosedTypeOf(typeof(IQueryHandler <>)))
            .AsImplementedInterfaces()
            .AsSelf()
            .InstancePerLifetimeScope();

            // query validator source
            appStartup.GetContainerBuilder()
            .RegisterInstance(new QueryValidatorSource(cqrsAssembly))
            .As <IQueryValidatorSource>()
            .SingleInstance();

            return(appStartup);
        }