示例#1
0
        private void DbUpdate(string startupAssembly, bool shortTransactions, bool skipRecompute)
        {
            RhetosHost CreateRhetosHost(Action <IRhetosHostBuilder> configureRhetosHost)
            {
                return(RhetosHost.CreateFrom(startupAssembly, builder =>
                {
                    builder.ConfigureConfiguration(configurationBuilder =>
                    {
                        // Default settings for dbupdate command:
                        configurationBuilder.AddKeyValue(ConfigurationProvider.GetKey((DatabaseOptions o) => o.SqlCommandTimeout), 0);
                        configurationBuilder.AddKeyValue(ConfigurationProvider.GetKey((ConfigurationProviderOptions o) => o.LegacyKeysWarning), true);
                        configurationBuilder.AddKeyValue(ConfigurationProvider.GetKey((LoggingOptions o) => o.DelayedLogTimout), 60.0);
                        // Standard configuration files can override the default settings:
                        configurationBuilder.AddJsonFile(DbUpdateOptions.ConfigurationFileName, optional: true);
                        // CLI switches can override the settings from configuration files:
                        if (shortTransactions)
                        {
                            configurationBuilder.AddKeyValue(ConfigurationProvider.GetKey((DbUpdateOptions o) => o.ShortTransactions), shortTransactions);
                        }
                        if (skipRecompute)
                        {
                            configurationBuilder.AddKeyValue(ConfigurationProvider.GetKey((DbUpdateOptions o) => o.SkipRecompute), skipRecompute);
                        }
                    });
                    configureRhetosHost.Invoke(builder);
                }));
            }

            var deployment = new ApplicationDeployment(CreateRhetosHost, _logProvider);

            deployment.UpdateDatabase();
            deployment.InitializeGeneratedApplication();
        }
        public void Initialize(RhetosHost rhetosHost, Action <ContainerBuilder> customRegistrations = null)
        {
            if (rhetosHost is null)
            {
                throw new ArgumentNullException(nameof(rhetosHost));
            }

            Initialize(rhetosHost.GetRootContainer(), customRegistrations);
        }
示例#3
0
        /// <summary>
        /// This method creates a thread-safe lifetime scope DI container to isolate unit of work in a separate database transaction.
        /// To commit changes to database, call <see cref="UnitOfWorkScope.CommitAndClose"/> at the end of the 'using' block.
        /// </summary>
        /// <remarks>
        /// In most cases it is preferred to use a <see cref="RhetosHost"/> instance, instead of this static method, for better control over the DI container.
        /// The static method is useful in some special cases, for example to optimize LINQPad scripts that can reuse the external static instance
        /// after recompiling the script.
        /// </remarks>
        /// <param name="rhetosAppAssemblyPath">
        /// Path to assembly where the CreateHostBuilder method is located.
        /// </param>
        /// <param name="registerCustomComponents">
        /// Register custom components that may override application's services and plugins.
        /// This is commonly used by utilities and tests that need to override host application's Rhetos components or register additional plugins.
        /// <para>
        /// Note that the transaction-scope component registration will not affect singleton components.
        /// To customize the behavior of singleton components use <see cref="RhetosHost"/> directly.
        /// </para>
        /// </param>
        /// /// <param name="configureServices">
        /// Configures host application's dependency injection components and configuration.
        /// </param>
        public static UnitOfWorkScope CreateScope(
            string rhetosAppAssemblyPath,
            Action <ContainerBuilder> registerCustomComponents = null,
            Action <HostBuilderContext, IServiceCollection> configureServices = null)
        {
            if (_singleRhetosHost == null)
            {
                lock (_singleContainerLock)
                    if (_singleRhetosHost == null)
                    {
                        _singleRhetosHostAssemblyPath = rhetosAppAssemblyPath;
                        _singleRhetosHost             = RhetosHost.CreateFrom(rhetosAppAssemblyPath, ConfigureRhetosHost, OverrideHostLogging + configureServices);
                    }
            }

            if (_singleRhetosHostAssemblyPath != rhetosAppAssemblyPath)
            {
                throw new FrameworkException($"Static {nameof(LinqPadRhetosHost)}.{nameof(CreateScope)} cannot be used for different" +
                                             $" application contexts: Provided folder 1: '{_singleRhetosHostAssemblyPath}', folder 2: '{rhetosAppAssemblyPath}'." +
                                             $" Use a {nameof(RhetosHost)} instances instead.");
            }

            return(_singleRhetosHost.CreateScope(registerCustomComponents));
        }
示例#4
0
 public RhetosScopeServiceProvider(RhetosHost rhetosHost, IUserInfo rhetosUser)
 {
     unitOfWorkScope = rhetosHost.CreateScope(builder => builder.RegisterInstance(rhetosUser));
 }