예제 #1
0
 public void EnsureLifecycle(IActivator activator)
 {
     if (Lifecycle == null)
     {
         Lifecycle = (ILifecycle)activator.Create(LifecycleType, activator);
     }
 }
예제 #2
0
        public async Task Execute()
        {
            Validate();

            var source = activator.Create(sourceType);

            Func <ISource, Task <IValueResult <object> > > recieve = s => s.RecieveAsync();

            IValueResult <object> recieved = await recieve(source as ISource);

            object value = recieved.Value;

            if (value == null)
            {
                throw new Exception("Empty source!");
            }

            foreach (var stagesType in stagesTypes)
            {
                var stage = activator.Create(stagesType);
                Func <IStage, Task <IValueResult <object> > > stageFunc = s => s.Execute(value);
                IValueResult <object> stageResult = await stageFunc((IStage)stage);

                value = stageResult.Value;
            }

            //for (int i = 0; i < stagesTypes.Count; i++)
            //{
            //    var stage = (IStage)activator.Create(stagesTypes[i]);
            //    var expression = expressions[i];
            //    var lambda =  Expression.Lambda<Func<IStage, object, Task<IValueResult<object>>>>(
            //        expression);

            //    value = lambda.Compile()(stage, value);
            //}

            var destination = (IDestination)activator.Create(destinationType);

            Func <IDestination, Task <IActionResult> > send = s => s.SendAsync(value);

            var completed = await send(destination);

            Console.WriteLine("Completed!");
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override object Create(NLite.Mini.Context.IComponentContext context)
        {
            var impType = context.Component.Implementation;
            //if (impType.IsOpenGenericType())
            //    impType = impType.MakeCloseGenericType(context.GenericParameters);

            var  Kernel       = context.Kernel;
            var  proxyFactory = Kernel.Get <IProxyFactory>();
            bool createProxy  = proxyFactory != null;

            if (createProxy == false)
            {
                return(Real.Create(context));
            }

            object instance = null;

            object[] args = null;

            if (proxyFactory.RequiresTargetInstance(Kernel, context.Component))
            {
                instance = Real.Create(context);
            }
            else if (!typeof(DefaultActivator).IsAssignableFrom(Real.GetType()))
            {
                instance = Real.Create(context);
            }
            else
            {
                args = GetConstructurArgs(context);
            }

            try
            {
                instance = proxyFactory.Create(context, instance, args);
            }
            catch (Exception ex)
            {
                throw new ActivatorException("ComponentActivator: could not proxy " + impType.FullName, ex);
            }

            return(instance);
        }
예제 #4
0
    public object Create()
    {
        var arguments = new object[argumentFactories.Length];

        for (var i = 0; i < argumentFactories.Length; i++)
        {
            arguments[i] = argumentFactories[i].Create();
        }

        return(activator.Create(arguments));
    }
예제 #5
0
        public object Deserialize(ValueStream stream, Type dataType)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(nameof(Serializer));
            }

            if (dataType == null)
            {
                throw new ArgumentNullException(nameof(dataType));
            }

            if (!dataType.IsValueType || Nullable.GetUnderlyingType(dataType) != null)
            {
                if (stream.ReadByte() == 0)
                {
                    return(null);
                }
            }

            var dto = converterContainer.TryGetDto(dataType);

            if (dto?.Converter != null)
            {
                return(dto.Converter.DeserializeObject(stream, dataType));
            }

            if (stream.ReadByte() == 1)
            {
                var aliasBytes = new byte[4];
                stream.Read(aliasBytes, 0, aliasBytes.Length);

                var alias = new UnifiedUnion(aliasBytes[0], aliasBytes[1], aliasBytes[2], aliasBytes[3]).Int32;

                dataType = converterContainer.GetTypeFromAlias(alias);
            }

            var instance = activator.Create(dataType);

            var propertyInfo = EnsureProperties(dataType);

            for (var i = 0; i < propertyInfo.Length; i++)
            {
                propertyInfo[i].SetValue(instance, Deserialize(stream, propertyInfo[i].PropertyType));
            }

            return(instance);
        }
예제 #6
0
        public object Create(IKernel kernel, IBinding binding)
        {
#pragma warning disable 420
            if (constructor == null)
            {
                Interlocked.CompareExchange(ref constructor, FindBestConstructor(kernel, binding), null);
                Interlocked.CompareExchange(ref activator, ActivatorCache.GetActivator(constructor.Constructor), null);
            }
#pragma warning restore 420

            var arguments = ResolveParameters(kernel, binding, constructor);
            var instance  = activator.Create(arguments);

            for (var j = 0; j < injectors.Length; j++)
            {
                injectors[j].Inject(kernel, binding, metadata, instance);
            }

            return(instance);
        }
예제 #7
0
        public override object DeserializeObject(ValueStream stream, Type type)
        {
            var elementType = type.GetGenericArguments()[0];

            var length = new UnifiedUnion(
                (byte)stream.ReadByte(),
                (byte)stream.ReadByte(),
                (byte)stream.ReadByte(),
                (byte)stream.ReadByte()).Int32;

            if (type.IsInterface)
            {
                type = OpenListType.MakeGenericType(elementType);
            }
            var list = (IList)activator.Create(type);

            for (var i = 0; i < length; i++)
            {
                list.Add(serializer.Deserialize(stream, elementType));
            }

            return(list);
        }
예제 #8
0
 public object Resolve(Type type, object[] arguments)
 {
     return(instance ?? (instance = activator.Create(type, arguments)));
 }
예제 #9
0
 public object NewActivator0()
 {
     return(newActivator0.Create(null));
 }
예제 #10
0
 public object EmitActivator8()
 {
     return(emitActivator8B.Create(Parameters8));
 }
예제 #11
0
 public object EmitDelegateActivator8()
 {
     return(emitDelegateActivator8.Create(Parameters8));
 }
예제 #12
0
 public object ExpressionDelegateActivator8()
 {
     return(expressionDelegateActivator8.Create(Parameters8));
 }
예제 #13
0
 public object ReflectionActivatorActivator8()
 {
     return(activatorActivator8.Create(Parameters8));
 }
예제 #14
0
 public object ReflectionActivatorActivator0()
 {
     return(activatorActivator0.Create(null));
 }
예제 #15
0
 public object EmitActivator1()
 {
     return(emitActivator1B.Create(Parameters1));
 }
예제 #16
0
 public object EmitDelegateActivator1()
 {
     return(emitDelegateActivator1.Create(Parameters1));
 }
예제 #17
0
 public object Resolve(Type type, object[] arguments)
 {
     return(activator.Create(type, arguments));
 }
예제 #18
0
 public object NewActivator1()
 {
     return(newActivator1.Create(Parameters1));
 }
예제 #19
0
 public object EmitActivator0()
 {
     return(emitActivator0B.Create(null));
 }
예제 #20
0
 public object EmitDelegateActivator0()
 {
     return(emitDelegateActivator0.Create(null));
 }
예제 #21
0
 public object ExpressionDelegateActivator0()
 {
     return(expressionDelegateActivator0.Create(null));
 }
예제 #22
0
 public object NewActivator8()
 {
     return(newActivator8.Create(Parameters8));
 }
예제 #23
0
 public object ReflectionActivatorActivator1()
 {
     return(activatorActivator1.Create(Parameters1));
 }
예제 #24
0
 public object ReflactionCtorActivator0()
 {
     return(ctorActivator0.Create(null));
 }