Beispiel #1
0
        /// <summary>
        /// Registering DI components
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="store">The configuration store.</param>
        protected override void RegisterWindsorComponents(IWindsorContainer container, IConfigurationStore store)
        {
            if (this.installer == null)
            {
                Log.Information("Registering EF endpoint driver");
                try
                {
                    var installerTypes =
                        AppDomain.CurrentDomain.GetAssemblies()
                            .SelectMany(a => a.GetTypes())
                            .Where(t => t.IsSubclassOf(typeof(BaseEntityFrameworkInstaller)))
                            .ToList();

                    if (installerTypes.Count > 1)
                    {
                        throw new ConfigurationException(
                            $"There should be only one BaseEntityFrameworkInstaller, but found \n{string.Join(", \n", installerTypes.Select(t => t.FullName))}");
                    }

                    if (installerTypes.Count == 0)
                    {
                        throw new ConfigurationException($"There is no BaseEntityFrameworkInstaller");
                    }

                    this.installer =
                        (BaseEntityFrameworkInstaller)
                        installerTypes.Single().GetConstructor(new Type[0])?.Invoke(new object[0]);
                    if (this.installer == null)
                    {
                        throw new InvalidOperationException();
                    }
                }
                catch (ReflectionTypeLoadException e)
                {
                    foreach (var le in e.LoaderExceptions.Take(30))
                    {
                        Log.Logger.Error($"{le.Message}");
                    }

                    throw;
                }
            }

            if (this.installer != null)
            {
                DbConfiguration.SetConfiguration(this.installer.GetConfiguration());
                var baseConnectionManager = this.installer.CreateConnectionManager();

                container.Register(
                    Component.For<BaseConnectionManager>().Instance(baseConnectionManager).LifestyleSingleton());
            }
        }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Installer"/> class.
 /// </summary>
 /// <param name="installer">Entity framework driver installer</param>
 public Installer(BaseEntityFrameworkInstaller installer)
 {
     this.installer = installer;
 }