Пример #1
0
        //Property (EntityTable<>) instantiation must be performed here!
        public Database()
        {
            try
            {
                this._connection = AutofacModule.Container.Resolve <IConnection>();
                logger.LogInformation("Database object is instantiated SUCCESSFULLY: " + this.GetType().Name);
            }

            catch (Exception e)
            {
                logger.LogError("ERROR: " + e.Message);
                throw e;
            }


            this._options = AutofacModule.Container.Resolve <DatabaseOptions>();
            if (_options == null)
            {
                throw new DatabaseNotConfiguredException(this.GetType());
            }


            try
            {
                /* BEGIN: Injecting this database object to EntityTable<T>'s 'Database' property */
                var properties = this.GetType().GetProperties();
                logger.LogInformation(properties.ToString());
                foreach (var property in properties)
                {
                    /* BEGIN: Intantiating EntityTable<T> property of Database object */
                    var propertyName = property.Name;
                    logger.LogInformation(propertyName);
                    var propertyType            = property.PropertyType;
                    var propertyGenericArgument = propertyType.GetGenericArguments()[0];
                    var genericType             = typeof(EntityTable <>).MakeGenericType(propertyGenericArgument);
                    this.GetType().GetProperty(propertyName).SetValue(this, Activator.CreateInstance(genericType));
                    /* BEGIN: Intantiating EntityTable<T> property of Database object */

                    //Injecting EntityTable<T>'s Database property to this object
                    propertyType.GetProperty("Database")
                    .SetValue(this.GetType().GetProperty(propertyName).GetValue(this), this);
                }

                /* END: Injecting this database object to EntityTable<T>'s 'Database' property */
            }

            catch (Exception e)
            {
                logger.LogError("Database::ctor: " + e.Message);
            }
        }
 public DatabaseOptionsBuilder()
 {
     _databaseOptions = new DatabaseOptions();
 }