Ejemplo n.º 1
0
 public InitializerConfig(
     EntityFrameworkSection entityFrameworkSettings,
     KeyValueConfigurationCollection appSettings)
 {
     this._entityFrameworkSettings = entityFrameworkSettings;
     this._appSettings             = appSettings;
 }
Ejemplo n.º 2
0
 internal AppConfig(
     ConnectionStringSettingsCollection connectionStrings,
     KeyValueConfigurationCollection appSettings,
     EntityFrameworkSection entityFrameworkSettings,
     ProviderServicesFactory providerServicesFactory = null)
 {
     this._connectionStrings       = connectionStrings;
     this._appSettings             = appSettings ?? new KeyValueConfigurationCollection();
     this._entityFrameworkSettings = entityFrameworkSettings ?? new EntityFrameworkSection();
     this._providerServicesFactory = providerServicesFactory ?? new ProviderServicesFactory();
     this._providerServices        = new Lazy <IList <NamedDbProviderService> >((Func <IList <NamedDbProviderService> >)(() => (IList <NamedDbProviderService>) this._entityFrameworkSettings.Providers.OfType <ProviderElement>().Select <ProviderElement, NamedDbProviderService>((Func <ProviderElement, NamedDbProviderService>)(e => new NamedDbProviderService(e.InvariantName, this._providerServicesFactory.GetInstance(e.ProviderTypeName, e.InvariantName)))).ToList <NamedDbProviderService>()));
     if (this._entityFrameworkSettings.DefaultConnectionFactory.ElementInformation.IsPresent)
     {
         this._defaultConnectionFactory = new Lazy <IDbConnectionFactory>((Func <IDbConnectionFactory>)(() =>
         {
             DefaultConnectionFactoryElement connectionFactory = this._entityFrameworkSettings.DefaultConnectionFactory;
             try
             {
                 return((IDbConnectionFactory)Activator.CreateInstance(connectionFactory.GetFactoryType(), connectionFactory.Parameters.GetTypedParameterValues()));
             }
             catch (Exception ex)
             {
                 throw new InvalidOperationException(Strings.SetConnectionFactoryFromConfigFailed((object)connectionFactory.FactoryTypeName), ex);
             }
         }), true);
     }
     else
     {
         this._defaultConnectionFactory = this._defaultDefaultConnectionFactory;
     }
 }
Ejemplo n.º 3
0
        public InitializerConfig(EntityFrameworkSection entityFrameworkSettings, KeyValueConfigurationCollection appSettings)
        {
            DebugCheck.NotNull(entityFrameworkSettings);
            DebugCheck.NotNull(appSettings);

            _entityFrameworkSettings = entityFrameworkSettings;
            _appSettings             = appSettings;
        }
Ejemplo n.º 4
0
        private static Mock <ProviderServicesFactory> CreateMockFactory(EntityFrameworkSection section)
        {
            var mockFactory = new Mock <ProviderServicesFactory>();

            section.Providers.OfType <ProviderElement>().Each(
                e =>
            {
                var mockServices = new Mock <DbProviderServices>();
                mockServices.Setup(m => m.GetService(typeof(string), null)).Returns((object)e.InvariantName);
                mockFactory.Setup <DbProviderServices>(m => m.GetInstance(e.ProviderTypeName, e.InvariantName)).Returns(mockServices.Object);
            });
            return(mockFactory);
        }
Ejemplo n.º 5
0
        internal AppConfig(
            ConnectionStringSettingsCollection connectionStrings,
            KeyValueConfigurationCollection appSettings,
            EntityFrameworkSection entityFrameworkSettings,
            ProviderServicesFactory providerServicesFactory = null)
        {
            DebugCheck.NotNull(connectionStrings);

            _connectionStrings       = connectionStrings;
            _appSettings             = appSettings ?? new KeyValueConfigurationCollection();
            _entityFrameworkSettings = entityFrameworkSettings ?? new EntityFrameworkSection();
            _providerServicesFactory = providerServicesFactory ?? new ProviderServicesFactory();

            _providerServices = new Lazy <IList <NamedDbProviderService> >(
                () => _entityFrameworkSettings
                .Providers
                .OfType <ProviderElement>()
                .Select(
                    e => new NamedDbProviderService(
                        e.InvariantName,
                        _providerServicesFactory.GetInstance(e.ProviderTypeName, e.InvariantName)))
                .ToList());

            if (_entityFrameworkSettings.DefaultConnectionFactory.ElementInformation.IsPresent)
            {
                _defaultConnectionFactory = new Lazy <IDbConnectionFactory>(
                    () =>
                {
                    var setting = _entityFrameworkSettings.DefaultConnectionFactory;

                    try
                    {
                        var type = setting.GetFactoryType();
                        var args = setting.Parameters.GetTypedParameterValues();
                        return((IDbConnectionFactory)Activator.CreateInstance(type, args));
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidOperationException(
                            Strings.SetConnectionFactoryFromConfigFailed(setting.FactoryTypeName), ex);
                    }
                }, isThreadSafe: true);
            }
            else
            {
                _defaultConnectionFactory = _defaultDefaultConnectionFactory;
            }
        }
Ejemplo n.º 6
0
        internal AppConfig(
            ConnectionStringSettingsCollection connectionStrings,
            KeyValueConfigurationCollection appSettings,
            EntityFrameworkSection entityFrameworkSettings)
        {
            DebugCheck.NotNull(connectionStrings);

            _connectionStrings       = connectionStrings;
            _appSettings             = appSettings ?? new KeyValueConfigurationCollection();
            _entityFrameworkSettings = entityFrameworkSettings ?? new EntityFrameworkSection();

            if (_entityFrameworkSettings.DefaultConnectionFactory.ElementInformation.IsPresent)
            {
                _defaultConnectionFactory = new Lazy <IDbConnectionFactory>(
                    () =>
                {
                    var setting = _entityFrameworkSettings.DefaultConnectionFactory;

                    try
                    {
                        var type = setting.GetFactoryType();
                        var args = setting.Parameters.GetTypedParameterValues();
                        return((IDbConnectionFactory)Activator.CreateInstance(type, args));
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidOperationException(
                            Strings.SetConnectionFactoryFromConfigFailed(setting.FactoryTypeName), ex);
                    }
                }, isThreadSafe: true);
            }
            else
            {
                _defaultConnectionFactory = _defaultDefaultConnectionFactory;
            }
        }
Ejemplo n.º 7
0
 public QueryCacheConfig(EntityFrameworkSection entityFrameworkSection)
 {
     this._entityFrameworkSection = entityFrameworkSection;
 }
Ejemplo n.º 8
0
        public QueryCacheConfig(EntityFrameworkSection entityFrameworkSection)
        {
            DebugCheck.NotNull(entityFrameworkSection);

            _entityFrameworkSection = entityFrameworkSection;
        }
Ejemplo n.º 9
0
        public ContextConfig(EntityFrameworkSection entityFrameworkSettings)
        {
            DebugCheck.NotNull(entityFrameworkSettings);

            _entityFrameworkSettings = entityFrameworkSettings;
        }