private async Task <object> CreateInstanceAsync(Type interfaceType, ComponentDescriptor componentDescriptor, Action <string> progressCallback, ComponentDescriptor[] resolveStack)
        {
            ComponentDescriptor[] ResolveStack      = this.CheckPreventRecursion(resolveStack, componentDescriptor);
            ComponentInstance     ComponentInstance = this.instances[componentDescriptor];

            Func <Func <Task <object> >, Task <object> > RunCreate = componentDescriptor.MustCreateOnUiThread ? this.Repository.RunOnUiThread : Task.Run;
            object Instance = await RunCreate(async() => await ComponentInstance.CreateInstanceAsync(interfaceType, this, progressCallback, ResolveStack));

            return(Instance);
        }
 internal ComponentDescriptor(ComponentRepository componentRepository, Type type, object config, ComponentRepository privateRepository)
 {
     this.Repository           = componentRepository;
     this.Type                 = type;
     this.Name                 = ComponentDescriptor.GetComponentName(type);
     this.Config               = config;
     this.ConfigType           = config?.GetType();
     this.PrivateRepository    = privateRepository;
     this.MustCreateOnUiThread = ComponentDescriptor.GetComponentUiThreadAffinity(type, this.Repository);
 }
        private object CreateInstance(Type interfaceType, ComponentDescriptor componentDescriptor, Action <string> progressCallback, ComponentDescriptor[] resolveStack)
        {
            ComponentDescriptor[] ResolveStack      = this.CheckPreventRecursion(resolveStack, componentDescriptor);
            ComponentInstance     ComponentInstance = this.instances[componentDescriptor];

            if (componentDescriptor.MustCreateOnUiThread && this.Repository.IsUiThread() == false)
            {
                throw new ArgumentException(@"Attempting to synchronously create a compontent instance that needs to be created on the UI thread from a non-ui thread.\nEither marshal the creation to the UI Thread, or use the async creation method that implicitly marshals if needed");
            }

            object Instance = ComponentInstance.CreateInstance(interfaceType, this, progressCallback, ResolveStack);

            return(Instance);
        }
Beispiel #4
0
        public ComponentInstance this[ComponentDescriptor componentDescriptor]
        {
            get
            {
                foreach (ComponentInstance ComponentInstance in this.innerList)
                {
                    if (ComponentInstance.Descriptor == componentDescriptor)
                    {
                        return(ComponentInstance);
                    }
                }

                ComponentInstance NewComponentInstance = componentDescriptor.CreateComponentInstance();
                this.innerList.Add(NewComponentInstance);
                this.InvokeComponentInstanceAdded(NewComponentInstance);
                return(NewComponentInstance);
            }
        }
 internal SharedComponentInstance(ComponentDescriptor componentDescriptor)
     : base(componentDescriptor)
 {
 }
Beispiel #6
0
 internal SingletonComponentInstance(ComponentDescriptor componentDescriptor)
     : base(componentDescriptor)
 {
 }
 private ComponentDescriptor[] CheckPreventRecursion(ComponentDescriptor[] resolveStack, ComponentDescriptor descriptor)
 {
     if (resolveStack.Contains(descriptor))
     {
         string Message = $"Recursion during creation of component '{descriptor.Name}':\n{string.Join(" -> ", resolveStack.Reverse().ConvertTo(value => value.ToString()).ToArray())}";
         throw new InvalidOperationException(Message);
     }
     else
     {
         return(resolveStack.Union(new[] { descriptor }).ToArray());
     }
 }
Beispiel #8
0
 internal SimpleComponentInstance(ComponentDescriptor componentDescriptor)
     : base(componentDescriptor)
 {
 }
 internal ComponentInstance(ComponentDescriptor componentDescriptor)
 {
     this.Descriptor = componentDescriptor;
 }