Exemple #1
0
        /// <summary>
        /// Returns a Dummy request scope for use in unit testing, with mock objects representing things like Session
        /// </summary>
        /// <returns>A Dummy request scope for use in unit testing, with mock objects representing things like Session</returns>
        public static PerRequestServiceScope CreateDummy()
        {
            PerRequestServiceScope ServiceScope = new PerRequestServiceScope();
            DefaultHttpContext     context      = new DefaultHttpContext
            {
                Session = new MockHttpSession()
            };

            ServiceScope.RequestProvider.Add(context);
            context.RequestServices = ServiceScope.ServiceProvider;
            return(ServiceScope);
        }
Exemple #2
0
        public async Task Invoke(HttpContext context)
        {
            if (context is null)
            {
                throw new System.ArgumentNullException(nameof(context));
            }

            using PerRequestServiceScope ServiceScope = new PerRequestServiceScope();
            ServiceScope.RequestProvider.Add(context);
            context.RequestServices = ServiceScope.ServiceProvider;

            await this._next(context);
        }
Exemple #3
0
        public static void ConfigureDatabase()
        {
            IPersistenceContextMigrator migrator = DependencyEngine.GetService <IPersistenceContextMigrator>();

            if (migrator is null)
            {
                throw new ArgumentNullException(nameof(migrator), "No persistence context migrator was found registered with the dependency injector, which may mean that no persistence context implementation is included in the solution");
            }

            PersistenceConfigured = migrator.IsConfigured;

            if (PersistenceConfigured)
            {
                migrator.Migrate();

                using PerRequestServiceScope ServiceScope = PerRequestScopeFactory.CreateDummy();

                new MessageBus(ServiceScope.ServiceProvider).Startup();
            }
        }