예제 #1
0
 protected virtual void OnObjectBuilt(ObjectBuildContext ctx)
 {
     if (this.ObjectBuilt != null)
     {
         this.ObjectBuilt(ctx);
     }
 }
예제 #2
0
            private object GetObject(IObjectSetting setting, Type expectedType)
            {
                var            builderName = setting.Builder;
                IObjectBuilder builder     = null;

                if (!string.IsNullOrEmpty(builderName))
                {
                    builder = this.GetServiceInternal <IObjectBuilder>(builderName);
                }
                var ctx = new ObjectBuildContext(this, setting, builder, null);

                this.OnObjectBuilding(ctx);
                if (ctx.ObjectInstance == null && builder != null)
                {
                    ctx.ObjectInstance = builder.CreateObject(setting);
                }
                if (ctx.ObjectInstance == null)
                {
                    var mapTo = this.GetTypeNameInternal(setting.MapTo);
                    if (!string.IsNullOrEmpty(mapTo))
                    {
                        ctx.ObjectInstance = TypeHelper.CreateObject(mapTo, expectedType, true);
                    }
                    else
                    {
                        var typeName = this.GetTypeNameInternal(setting.TypeName);
                        if (!string.IsNullOrEmpty(typeName))
                        {
                            ctx.ObjectInstance = TypeHelper.CreateObject(typeName, expectedType, true);
                        }
                        else
                        {
                            throw new ConfigException("type attribute is required in <object />");
                        }
                    }
                }
                this.OnObjectBuilt(ctx);
                return(ctx.ObjectInstance);
            }