예제 #1
0
        /// <summary>
        /// Create a new instance of a grain
        /// </summary>
        /// <param name="context">The <see cref="IGrainActivationContext"/> for the executing action.</param>
        /// <returns>The newly created grain.</returns>
        public Grain CreateGrainInstance(IGrainActivationContext context)
        {
            var grain = (Grain)grainActivator.Create(context);

            // Inject runtime hooks into grain instance
            grain.Runtime  = this.grainRuntime.Value;
            grain.Identity = context.GrainIdentity;

            return(grain);
        }
예제 #2
0
        public Grain CreateGrainInstance(IGrainActivationContext context)
        {
            var grain = (Grain)_activator.Create(context);

            //Set the runtime and identity. This is equivalent to what Orleans' GrainCreator does
            //when creating new grains. It is messier but easier than trying to wrangle the values
            //in via a constructor which may or may exist on types inheriting from Grain.

            _runtimeProperty.SetValue(grain, _runtime);
            _identityField.SetValue(grain, context.GrainIdentity);

            return(grain);
        }
예제 #3
0
        /// <summary>
        /// Create a new instance of a grain
        /// </summary>
        /// <param name="context">The <see cref="IGrainActivationContext"/> for the executing action.</param>
        /// <returns>The newly created grain.</returns>
        public Grain CreateGrainInstance(IGrainActivationContext context)
        {
            var grain = (Grain)grainActivator.Create(context);

            // Inject runtime hooks into grain instance
            grain.Runtime  = this.grainRuntime.Value;
            grain.Identity = context.GrainIdentity;

            // wire up to lifecycle
            var participant = grain as ILifecycleParticipant <IGrainLifecycle>;

            participant?.Participate(context.ObservableLifecycle);

            return(grain);
        }
예제 #4
0
        public Grain CreateGrainInstance(IGrainActivationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var grain = (Grain)_activator.Create(context);

            var participant = grain as ILifecycleParticipant <IGrainLifecycle>;

            participant?.Participate(context.ObservableLifecycle);

            //Set the runtime and identity. This is equivalent to what Orleans' GrainCreator does
            //when creating new grains. It is messier but easier than trying to wrangle the values
            //in via a constructor which may or may exist on types inheriting from Grain.
            _runtimeProperty.SetValue(grain, _runtime);
            _identityField.SetValue(grain, context.GrainIdentity);

            return(grain);
        }