示例#1
0
 internal SandboxedHost(IHost host, IObjectAccessor accessor, MicroScheduler scheduler)
 {
     m_host = host;
     m_accessor = accessor;
     m_graphics = new SandboxedGraphics(host.Graphics);
     m_scheduler = scheduler;
 }
示例#2
0
 public EFFreeRepositoryProvider(
     IServiceProvider serviceProvider,
     IObjectAccessor <MiCakeEFCoreOptions> options)
 {
     _serviceProvider = serviceProvider;
     _options         = options.Value;
 }
示例#3
0
        public static bool TryGet(object target, out IObjectAccessor accessor)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (target is IDictionary <string, object> )
            {
                accessor = DictionaryStringObjectAccessor.Default;
                return(true);
            }

            var type           = target.GetType();
            var dictionaryType = type.GetBaseOrInterface(typeof(IDictionary <,>));

            if (dictionaryType == null)
            {
                if (target is IDictionary)
                {
                    accessor = Default;
                    return(true);
                }

                accessor = null;
                return(false);
            }
            var keyType   = dictionaryType.GetGenericArguments()[0];
            var valueType = dictionaryType.GetGenericArguments()[1];

            var accessorType = typeof(GenericDictionaryAccessor <,>).MakeGenericType(keyType, valueType);

            accessor = (IObjectAccessor)Activator.CreateInstance(accessorType);
            return(true);
        }
示例#4
0
        public void ShouldGenerateTypeFromData()
        {
            Dictionary <string, Type> typeDef = new Dictionary <string, Type>
            {
                { "StringProp", typeof(String) },
                { "IntProp", typeof(int) },
                { "DateProp", typeof(DateTime) },
                { "DoubleNullableProp", typeof(double?) }
            };

            Type t = TypeGenerator.MakeType("NewTypeA", typeDef);

            Assert.That("NewTypeA", Is.EqualTo(t.Name));

            var pi = t.GetField("StringProp");

            Assert.That(typeof(string), Is.EqualTo(pi.FieldType));

            pi = t.GetField("IntProp");
            Assert.That(typeof(int), Is.EqualTo(pi.FieldType));

            pi = t.GetField("DateProp");
            Assert.That(typeof(DateTime), Is.EqualTo(pi.FieldType));

            pi = t.GetField("DoubleNullableProp");
            Assert.That(typeof(double?), Is.EqualTo(pi.FieldType));

            IObjectAccessor a = (IObjectAccessor)Activator.CreateInstance(t);

            a["StringProp"] = "test";
            string s = (string)a["StringProp"];

            Assert.That(s, Is.EqualTo("test"));
        }
示例#5
0
        public static bool TryGet(Type type, out IObjectAccessor accessor)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (typeof(IDictionary).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()))
            {
                accessor = Default;
                return(true);
            }

            Type dictionaryType = type.GetBaseOrInterface(typeof(IDictionary <,>));

            accessor = null;
            if (dictionaryType == null)
            {
                return(false);
            }
            Type keyType   = dictionaryType.GetTypeInfo().GetGenericArguments()[0];
            Type valueType = dictionaryType.GetTypeInfo().GetGenericArguments()[1];

            Type accessorType = typeof(GenericDictionaryAccessor <,>).GetTypeInfo().MakeGenericType(keyType, valueType);

            accessor = (IObjectAccessor)Activator.CreateInstance(accessorType);
            return(true);
        }
示例#6
0
        /// <summary>
        /// Accepts a list of objects, and outputs the value of a specified property in each object.
        /// </summary>
        /// <param name="context">The template context.</param>
        /// <param name="span">The source span.</param>
        /// <param name="list">The input list.</param>
        /// <param name="member">The name of the property. An item must be an object and contains this property in order for this function to output its value.</param>
        /// <remarks>
        /// ```template-text
        /// {{
        /// products = [{title: "orange", type: "fruit"}, {title: "computer", type: "electronics"}, {title: "sofa", type: "furniture"}]
        /// products | array.map "type" | array.uniq | array.sort }}
        /// ```
        /// ```html
        /// [electronics, fruit, furniture]
        /// ```
        /// </remarks>
        public static IEnumerable Map(TemplateContext context, SourceSpan span, object list, string member)
        {
            if (list == null || member == null)
            {
                yield break;
            }

            var           enumerable = list as IEnumerable;
            List <object> realList   = enumerable?.Cast <object>().ToList() ?? new List <object>(1)
            {
                list
            };

            if (realList.Count == 0)
            {
                yield break;
            }

            foreach (var item in realList)
            {
                IObjectAccessor itemAccessor = context.GetMemberAccessor(item);
                if (itemAccessor.HasMember(context, span, item, member))
                {
                    itemAccessor.TryGetValue(context, span, item, member, out object value);
                    yield return(value);
                }
            }
        }
示例#7
0
        public static void FillPropertySets(this IObjectAccessor objectAccessor, IMappingProvider mappingProvider, object entityType, object entity, IDictionary <string, object> propertySets, IEnumerable <string> propertyNames, IEnumerable <string> excludePropertyNames)
        {
            HashSet <string> exclude = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            if (excludePropertyNames != null)
            {
                exclude = new HashSet <string>(excludePropertyNames, StringComparer.OrdinalIgnoreCase);
            }
            ITable table = mappingProvider.GetTable(entityType);

            foreach (string propertyName in propertyNames)
            {
                if (!exclude.Contains(propertyName))
                {
                    string propertyName2 = table.Columns[propertyName].PropertyName;
                    if (propertySets.ContainsKey(propertyName2))
                    {
                        propertySets[propertyName2] = objectAccessor.Get(entity, propertyName2);
                    }
                    else
                    {
                        propertySets.Add(propertyName2, objectAccessor.Get(entity, propertyName2));
                    }
                }
            }
        }
示例#8
0
        public static IDictionary <string, object> ToPropertySets(this IObjectAccessor objectAccessor, IMappingProvider mappingProvider, object entityType, object entity, IEnumerable <string> propertyNames, IEnumerable <string> excludePropertyNames)
        {
            Dictionary <string, object> propertySets = new Dictionary <string, object>();

            objectAccessor.FillPropertySets(mappingProvider, entityType, entity, propertySets, propertyNames, excludePropertyNames);
            return(propertySets);
        }
        /// <summary>
        /// 切换一个新的实体对象
        /// </summary>
        /// <param name="data"></param>
        public void Switch(object data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            if (data is IEntityExplain)
            {
                throw new ArgumentException(string.Format("类型[{0}]已经继承[{1}].", data.GetType().FullName, typeof(IEntityExplain).FullName));
            }
            if (EntityData == null || data.GetType() != EntityData.GetType())
            {
                Type sourceType;
                if (data is IEntity)
                {
                    sourceType = ((IEntity)data).EntityType;
                }
                else
                {
                    sourceType = data.GetType();
                }

                _accessor = Map.GetCheckedAccessor(sourceType);
            }
            EntityData = data;
        }
示例#10
0
 public RazorViewEngineVirtualFileProvider(IObjectAccessor <IServiceProvider> serviceProviderAccessor)
 {
     _serviceProviderAccessor = serviceProviderAccessor;
     _fileProvider            = new Lazy <IFileProvider>(
         () => serviceProviderAccessor.Value.GetRequiredService <IVirtualFileProvider>(),
         true
         );
 }
示例#11
0
 public EFRepositoryProvider(
     IServiceProvider serviceProvider,
     DomainMetadata domainMetadata,
     IObjectAccessor <MiCakeEFCoreOptions> options)
 {
     _serviceProvider        = serviceProvider;
     _aggregateRootsMetadata = domainMetadata.DomainObject.AggregateRoots;
     _options = options.Value;
 }
        public ObjectTypeMapper(IObjectAccessor <T> objAccessor)
        {
            if (objAccessor == null)
            {
                throw new ArgumentNullException("objAccessor");
            }

            this.objAccessor = objAccessor;
            Init();
        }
        public ObjectTypeMapper()
        {
            objAccessor = ObjectAccessorFinder.FindObjAccessor <T>();
            if (objAccessor == null)
            {
                throw new MapperException(string.Format("未能查找到{0}的访问器[{1}]。", typeof(T).FullName, typeof(IObjectAccessor <T>).FullName));
            }

            Init();
        }
示例#14
0
        /// <summary>
        /// Sorts the elements of the input list according to the value of each item or the value of the specified property of each object-type item.
        /// </summary>
        /// <param name="context">The template context.</param>
        /// <param name="span">The source span.</param>
        /// <param name="list">The input list.</param>
        /// <param name="member">The property name to sort according to its value. This is `null` by default, meaning that the item's value is used instead.</param>
        /// <returns>A list sorted according to the value of each item or the value of the specified property of each object-type item.</returns>
        /// <remarks>
        /// Sort by value:
        /// ```template-text
        /// {{ [10, 2, 6] | array.sort }}
        /// ```
        /// ```html
        /// [2, 6, 10]
        /// ```
        /// Sorts by object property's value:
        /// ```template-text
        /// {{
        /// products = [{title: "orange", type: "fruit"}, {title: "computer", type: "electronics"}, {title: "sofa", type: "furniture"}]
        /// products | array.sort "title" | array.map "title"
        /// }}
        /// ```
        /// ```html
        /// [computer, orange, sofa]
        /// ```
        /// </remarks>
        public static IEnumerable Sort(TemplateContext context, SourceSpan span, object list, string member = null)
        {
            if (list == null)
            {
                return(Enumerable.Empty <object>());
            }

            var enumerable = list as IEnumerable;

            if (enumerable == null)
            {
                return new ScriptArray(1)
                       {
                           list
                       }
            }
            ;

            List <object> realList = enumerable.Cast <object>().ToList();

            if (realList.Count == 0)
            {
                return(realList);
            }

            if (string.IsNullOrEmpty(member))
            {
                realList.Sort();
            }
            else
            {
                realList.Sort((a, b) =>
                {
                    IObjectAccessor leftAccessor  = context.GetMemberAccessor(a);
                    IObjectAccessor rightAccessor = context.GetMemberAccessor(b);

                    object leftValue  = null;
                    object rightValue = null;

                    if (!leftAccessor.TryGetValue(context, span, a, member, out leftValue))
                    {
                        context.TryGetMember?.Invoke(context, span, a, member, out leftValue);
                    }

                    if (!rightAccessor.TryGetValue(context, span, b, member, out rightValue))
                    {
                        context.TryGetMember?.Invoke(context, span, b, member, out rightValue);
                    }

                    return(Comparer <object> .Default.Compare(leftValue, rightValue));
                });
            }

            return(realList);
        }
示例#15
0
        public Queryable(DatabaseHelper database)
        {
            if (database == null)
            {
                throw new ArgumentNullException("database");
            }

            this.database = database;
            accessor      = Map.GetCheckedAccessor <T>();
            fields        = accessor.MetaInfo.GetProperties();
            Options       = SqlOptions.NoLock;
        }
示例#16
0
        public void SetValue(TemplateContext context, object valueToSet)
        {
            var             targetObject = GetTargetObject(context, true);
            IObjectAccessor accessor     = context.GetMemberAccessor(targetObject);

            string memberName = this.Member.Name;

            if (!accessor.TrySetValue(context, this.Span, targetObject, memberName, valueToSet))
            {
                throw new ScriptRuntimeException(this.Member.Span, string.Format(RS.CannotSetReadOnlyMember, this)); // unit test: 132-member-accessor-error3.txt
            }
        }
示例#17
0
        public object GetValue(TemplateContext context)
        {
            var targetObject = GetTargetObject(context, false);

            // In case TemplateContext.EnableRelaxedMemberAccess
            if (targetObject == null)
            {
                return(null);
            }

            IObjectAccessor accessor = context.GetMemberAccessor(targetObject);

            string memberName = this.Member.Name;

            object value;

            if (!accessor.TryGetValue(context, Span, targetObject, memberName, out value))
            {
                context.TryGetMember?.Invoke(context, Span, targetObject, memberName, out value);
            }

            return(value);
        }
 public ContainerService Instantiate(Type type, bool crearteNew, IObjectAccessor arguments)
 {
     var builder = new ContainerService.Builder(type, this, crearteNew, arguments);
     if (builder.Status != ServiceStatus.Ok)
         return builder.Build();
     var declaredName = builder.GetDeclaredName();
     if (!constructingServices.Add(declaredName))
     {
         var previous = GetTopBuilder();
         if (previous == null)
             throw new InvalidOperationException(string.Format("assertion failure, service [{0}]", declaredName));
         var message = string.Format("cyclic dependency {0}{1} -> {0}",
             type.FormatName(), previous.Type == type ? "" : " ...-> " + previous.Type.FormatName());
         var cycleBuilder = new ContainerService.Builder(type, this, false, null);
         cycleBuilder.SetError(message);
         return cycleBuilder.Build();
     }
     stack.Add(builder);
     var expandResult = TryExpandUnions(Container.Configuration);
     if (expandResult != null)
     {
         var poppedContracts = Contracts.PopMany(expandResult.Length);
         foreach (var c in expandResult.CartesianProduct())
         {
             var childService = Resolve(new ServiceName(builder.Type, c));
             builder.LinkTo(Container.containerContext, childService, null);
             if (builder.Status.IsBad())
                 break;
         }
         Contracts.AddRange(poppedContracts);
     }
     else
         Container.Instantiate(builder);
     stack.RemoveLast();
     constructingServices.Remove(declaredName);
     return builder.Build();
 }
示例#19
0
        /// <summary>
        /// Instantiates a new object from the provided data.
        /// Type is generated automatically or picked up an existing one with the matching name.
        /// All null values will be represented as properties with "System.Object" type
        /// </summary>
        /// <param name="typeName">Type name. When null, a new unique name is generated</param>
        /// <param name="objDef">List of property names and corresponding values. Property type is inferred from the value type</param>
        /// <returns>Instantiated object</returns>
        public static IObjectAccessor MakeObject(string typeName, IEnumerable <KeyValuePair <string, object> > objDef)
        {
            s_lock.EnterUpgradeableReadLock();
            Type newT;
            var  defEntries = objDef as IList <KeyValuePair <string, object> > ?? objDef.ToList();

            try
            {
                newT = GetType(typeName) ?? MakeType(MakeTypeDef(typeName, defEntries));
            }
            finally
            {
                s_lock.ExitUpgradeableReadLock();
            }

            IObjectAccessor obj = (IObjectAccessor)Activator.CreateInstance(newT);

            foreach (var entry in defEntries)
            {
                obj[entry.Key] = entry.Value;
            }

            return(obj);
        }
 internal SandboxedObjectAccessor(IObjectAccessor accessor)
 {
     _accessor = accessor;
 }
 public DefaultDapperImp(IObjectAccessor <DapperOptions> objectAccessor) : base(objectAccessor?.Value.DefaultConnectStrName)
 {
 }
示例#22
0
 public AbpUserClaimsFactory(IObjectAccessor <IUserClaimsPrincipalFactory <TUser> > inner,
                             UserManager <TUser> userManager)
 {
     _inner       = inner;
     _userManager = userManager;
 }
 public Builder(Type type, ResolutionContext context, bool createNew, IObjectAccessor arguments)
 {
     Arguments = arguments;
     CreateNew = createNew;
     target = new ContainerService {Type = type};
     Context = context;
     DeclaredContracts = context.Contracts.ToArray();
     try
     {
         Configuration = context.Container.GetConfiguration(Type, context);
     }
     catch (Exception e)
     {
         SetError(e);
         return;
     }
     SetComment(Configuration.Comment);
     foreach (var contract in Configuration.Contracts)
     {
         if (usedContractNames == null)
             usedContractNames = new List<string>();
         if (!usedContractNames.Contains(contract, StringComparer.OrdinalIgnoreCase))
             usedContractNames.Add(contract);
     }
 }
示例#24
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="sqlProvider">需要传入类型,考虑到动态生成DbSession,不能用泛型</param>
 /// <param name="connectionString">数据库连接字符串</param>
 /// <param name="sqlTracers">可以指定多个sql语句跟踪器,如果为null则不会有任何追踪</param>
 public DbSession(ISqlProvider sqlProvider, string connectionString, IObjectAccessor objectAccessor, IMappingProvider mappingProvider, ISqlTracer[] sqlTracers)
     : base(sqlProvider, connectionString, sqlTracers)
 {
     ObjectAccessor  = objectAccessor;
     MappingProvider = mappingProvider;
 }
示例#25
0
        private object GetOrSetValue(TemplateContext context, object valueToSet, bool setter)
        {
            object value = null;

            var targetObject = context.GetValue(Target);

            if (targetObject == null)
            {
                if (context.EnableRelaxedMemberAccess)
                {
                    return(null);
                }
                else
                {
                    // unit test: 130-indexer-accessor-error1.txt
                    throw new ScriptRuntimeException(Target.Span, string.Format(RS.NoIndexForNull, Target, this));
                }
            }

            var index = context.Evaluate(Index);

            if (index == null)
            {
                if (context.EnableRelaxedMemberAccess)
                {
                    return(null);
                }
                else
                {
                    // unit test: 130-indexer-accessor-error2.txt
                    throw new ScriptRuntimeException(Index.Span, string.Format(RS.NoNullIndex, Target, this));
                }
            }

            if (targetObject is IDictionary || targetObject is ScriptObject)
            {
                IObjectAccessor accessor      = context.GetMemberAccessor(targetObject);
                string          indexAsString = context.ToString(Index.Span, index);

                if (setter)
                {
                    if (!accessor.TrySetValue(context, Span, targetObject, indexAsString, valueToSet))
                    {
                        throw new ScriptRuntimeException(Index.Span, string.Format(RS.CannotSetReadOnlyIndexMember, indexAsString, Target)); // unit test: 130-indexer-accessor-error3.txt
                    }
                }
                else
                {
                    if (!accessor.TryGetValue(context, Span, targetObject, indexAsString, out value))
                    {
                        context.TryGetMember?.Invoke(context, Span, targetObject, indexAsString, out value);
                    }
                }
            }
            else
            {
                IListAccessor accessor = context.GetListAccessor(targetObject);
                if (accessor == null)
                {
                    throw new ScriptRuntimeException(Target.Span,
                                                     string.Format(RS.TargetObjectNotList, targetObject, targetObject.GetType().Name, Target, this)); // unit test: 130-indexer-accessor-error4.txt
                }
                int i = context.ToInt(Index.Span, index);

                // Allow negative index from the end of the array
                if (i < 0)
                {
                    i = accessor.GetLength(context, Span, targetObject) + i;
                }

                if (i >= 0)
                {
                    if (setter)
                    {
                        accessor.SetValue(context, Span, targetObject, i, valueToSet);
                    }
                    else
                    {
                        value = accessor.GetValue(context, Span, targetObject, i);
                    }
                }
            }
            return(value);
        }
        internal ContainerService ResolveCore(ServiceName name, bool createNew, IObjectAccessor arguments, ResolutionContext context)
        {
            var pushedContracts = context.Contracts.Push(name.Contracts);
            var declaredName = new ServiceName(name.Type, context.Contracts.Snapshot());
            if (context.HasCycle(declaredName))
            {
                var message = string.Format("cyclic dependency for service [{0}], stack\r\n{1}",
                    declaredName.Type.FormatName(), context.FormatStack() + "\r\n\t" + declaredName);
                context.Contracts.RemoveLast(pushedContracts.pushedContractsCount);
                return ContainerService.Error(declaredName, message);
            }
            if (!pushedContracts.isOk)
            {
                const string messageFormat = "contract [{0}] already declared, stack\r\n{1}";
                var message = string.Format(messageFormat, pushedContracts.duplicatedContractName,
                    context.FormatStack() + "\r\n\t" + name);
                context.Contracts.RemoveLast(pushedContracts.pushedContractsCount);
                return ContainerService.Error(name, message);
            }
            context.ConstructingServices.Add(declaredName);

            ServiceConfiguration configuration = null;
            Exception configurationException = null;
            try
            {
                configuration = GetConfiguration(declaredName.Type, context);
            }
            catch (Exception e)
            {
                configurationException = e;
            }
            var actualName = configuration != null && configuration.FactoryDependsOnTarget && context.Stack.Count > 0
                ? declaredName.AddContracts(context.TopBuilder.Type.FormatName())
                : declaredName;
            ContainerServiceId id = null;
            if (!createNew)
            {
                id = instanceCache.GetOrAdd(actualName, createId);
                var acquireResult = id.AcquireInstantiateLock();
                if (!acquireResult.acquired)
                {
                    context.ConstructingServices.Remove(declaredName);
                    context.Contracts.RemoveLast(pushedContracts.pushedContractsCount);
                    return acquireResult.alreadyConstructedService;
                }
            }
            var builder = new ContainerService.Builder(actualName);
            context.Stack.Add(builder);
            builder.Context = context;
            builder.DeclaredContracts = actualName.Contracts;
            if (configuration == null)
                builder.SetError(configurationException);
            else
            {
                builder.SetConfiguration(configuration);
                builder.ExpandedUnions = context.Contracts.TryExpandUnions(Configuration);
                if (builder.ExpandedUnions.HasValue)
                {
                    var poppedContracts = context.Contracts.PopMany(builder.ExpandedUnions.Value.contracts.Length);
                    foreach (var c in builder.ExpandedUnions.Value.contracts.CartesianProduct())
                    {
                        var childService = ResolveCore(new ServiceName(name.Type, c), createNew, arguments, context);
                        builder.LinkTo(containerContext, childService, null);
                        if (builder.Status.IsBad())
                            break;
                    }
                    context.Contracts.PushNoCheck(poppedContracts);
                }
                else
                {
                    builder.CreateNew = createNew;
                    builder.Arguments = arguments;
                    Instantiate(builder);
                }
            }
            context.ConstructingServices.Remove(declaredName);
            context.Contracts.RemoveLast(pushedContracts.pushedContractsCount);
            context.Stack.RemoveLast();
            var result = builder.GetService();
            if (id != null)
                id.ReleaseInstantiateLock(builder.Context.AnalizeDependenciesOnly ? null : result);
            return result;
        }
示例#27
0
        /// <summary>
        /// 获取对象访问器(必须为单例模式的注册类型)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="services"></param>
        /// <param name="accessor"></param>
        /// <returns></returns>
        public static bool TryGetObjectAccessor <T>(this IServiceCollection services, out IObjectAccessor <T>?accessor) where T : class
        {
            var serviceDescriptor = services.FirstOrDefault(m => m.ServiceType == typeof(IObjectAccessor <T>));

            if (serviceDescriptor is null ||
                serviceDescriptor.Lifetime != ServiceLifetime.Singleton)
            {
                accessor = null;
                return(false);
            }
            accessor = serviceDescriptor.ImplementationInstance as IObjectAccessor <T>;
            return(accessor is not null);
        }
示例#28
0
        public DapperExtension(IObjectAccessor <DapperOptions> objectAccessor)
        {
            _objectAccessor = objectAccessor;

            _connectionString = _objectAccessor.Value?.DefaultConnectStrName;
        }
        internal ContainerService ResolveCore(ServiceName name, bool createNew, IObjectAccessor arguments, ResolutionContext context)
        {
            var pushedContracts = context.Contracts.Push(name.Contracts);
            var declaredName    = new ServiceName(name.Type, context.Contracts.Snapshot());

            if (context.HasCycle(declaredName))
            {
                var message = string.Format("cyclic dependency for service [{0}], stack\r\n{1}",
                                            declaredName.Type.FormatName(), context.FormatStack() + "\r\n\t" + declaredName);
                context.Contracts.RemoveLast(pushedContracts.pushedContractsCount);
                return(ContainerService.Error(declaredName, message));
            }
            if (!pushedContracts.isOk)
            {
                const string messageFormat = "contract [{0}] already declared, stack\r\n{1}";
                var          message       = string.Format(messageFormat, pushedContracts.duplicatedContractName,
                                                           context.FormatStack() + "\r\n\t" + name);
                context.Contracts.RemoveLast(pushedContracts.pushedContractsCount);
                return(ContainerService.Error(name, message));
            }
            context.ConstructingServices.Add(declaredName);

            ServiceConfiguration configuration          = null;
            Exception            configurationException = null;

            try
            {
                configuration = GetConfiguration(declaredName.Type, context);
            }
            catch (Exception e)
            {
                configurationException = e;
            }
            var actualName = configuration != null && configuration.FactoryDependsOnTarget && context.Stack.Count > 0
                                ? declaredName.AddContracts(context.TopBuilder.Type.FormatName())
                                : declaredName;
            ContainerServiceId id = null;

            if (!createNew)
            {
                id = instanceCache.GetOrAdd(actualName, createId);
                var acquireResult = id.AcquireInstantiateLock();
                if (!acquireResult.acquired)
                {
                    context.ConstructingServices.Remove(declaredName);
                    context.Contracts.RemoveLast(pushedContracts.pushedContractsCount);
                    return(acquireResult.alreadyConstructedService);
                }
            }
            var builder = new ContainerService.Builder(actualName);

            context.Stack.Add(builder);
            builder.Context           = context;
            builder.DeclaredContracts = actualName.Contracts;
            if (configuration == null)
            {
                builder.SetError(configurationException);
            }
            else
            {
                builder.SetConfiguration(configuration);
                builder.ExpandedUnions = context.Contracts.TryExpandUnions(Configuration);
                if (builder.ExpandedUnions.HasValue)
                {
                    var poppedContracts = context.Contracts.PopMany(builder.ExpandedUnions.Value.contracts.Length);
                    foreach (var c in builder.ExpandedUnions.Value.contracts.CartesianProduct())
                    {
                        var childService = ResolveCore(new ServiceName(name.Type, c), createNew, arguments, context);
                        builder.LinkTo(containerContext, childService, null);
                        if (builder.Status.IsBad())
                        {
                            break;
                        }
                    }
                    context.Contracts.PushNoCheck(poppedContracts);
                }
                else
                {
                    builder.CreateNew = createNew;
                    builder.Arguments = arguments;
                    Instantiate(builder);
                }
            }
            context.ConstructingServices.Remove(declaredName);
            context.Contracts.RemoveLast(pushedContracts.pushedContractsCount);
            context.Stack.RemoveLast();
            var result = builder.GetService();

            if (id != null)
            {
                id.ReleaseInstantiateLock(builder.Context.AnalizeDependenciesOnly ? null : result);
            }
            return(result);
        }
示例#30
0
 public Field(MemberInfo memberInfo, IObjectAccessor <T> objectAccessor)
     : base(memberInfo, objectAccessor)
 {
 }