public void EnsureLifecycle(IActivator activator) { if (Lifecycle == null) { Lifecycle = (ILifecycle)activator.Create(LifecycleType, activator); } }
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!"); }
/// <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); }
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)); }
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); }
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); }
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); }
public object Resolve(Type type, object[] arguments) { return(instance ?? (instance = activator.Create(type, arguments))); }
public object NewActivator0() { return(newActivator0.Create(null)); }
public object EmitActivator8() { return(emitActivator8B.Create(Parameters8)); }
public object EmitDelegateActivator8() { return(emitDelegateActivator8.Create(Parameters8)); }
public object ExpressionDelegateActivator8() { return(expressionDelegateActivator8.Create(Parameters8)); }
public object ReflectionActivatorActivator8() { return(activatorActivator8.Create(Parameters8)); }
public object ReflectionActivatorActivator0() { return(activatorActivator0.Create(null)); }
public object EmitActivator1() { return(emitActivator1B.Create(Parameters1)); }
public object EmitDelegateActivator1() { return(emitDelegateActivator1.Create(Parameters1)); }
public object Resolve(Type type, object[] arguments) { return(activator.Create(type, arguments)); }
public object NewActivator1() { return(newActivator1.Create(Parameters1)); }
public object EmitActivator0() { return(emitActivator0B.Create(null)); }
public object EmitDelegateActivator0() { return(emitDelegateActivator0.Create(null)); }
public object ExpressionDelegateActivator0() { return(expressionDelegateActivator0.Create(null)); }
public object NewActivator8() { return(newActivator8.Create(Parameters8)); }
public object ReflectionActivatorActivator1() { return(activatorActivator1.Create(Parameters1)); }
public object ReflactionCtorActivator0() { return(ctorActivator0.Create(null)); }