public void ResolveTest()
        {
            using (var container = new WindsorContainer())
            {
                var resolver = new ActorServiceResolver(container.Kernel, typeof(TestActorService))
                {
                };

                var context  = MockStatefulServiceContextFactory.Default;
                var typeInfo = ActorTypeInformation.Get(typeof(TestActor));

                Assert.Throws <ComponentNotFoundException>(() => resolver.Resolve(context, typeInfo));

                container.Register(Component.For <TestActorService>().LifestyleTransient());

                var service = resolver.Resolve(context, typeInfo);

                Assert.NotNull(service);
                var testService = Assert.IsType <TestActorService>(service);

                Assert.Null(testService.StateManagerFactory);
                Assert.Null(testService.ActorFactory);
                Assert.Null(testService.StateProvider);
                Assert.Null(testService.Settings);
                Assert.Same(typeInfo, testService.ActorTypeInfo);
                Assert.Same(context, testService.Context);

                // ReSharper disable once ConvertToLocalFunction -- Local function doesn't equal a realized Func<>
                Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactoryMock =
                    (actor, provider) => new MockActorStateManager();

                // ReSharper disable once ConvertToLocalFunction -- Local function doesn't equal a realized Func<>
                Func <ActorService, ActorId, ActorBase> actorFactoryMock =
                    (s, id) => new TestActor(s, id);

                var stateProviderMock = new Mock <IActorStateProvider>();

                var settings = new ActorServiceSettings();

                resolver = new ActorServiceResolver(container.Kernel, typeof(TestActorService))
                {
                    StateManagerFactory = stateManagerFactoryMock,
                    ActorFactory        = actorFactoryMock,
                    StateProvider       = stateProviderMock.Object,
                    Settings            = settings
                };

                service = resolver.Resolve(context, typeInfo);

                Assert.NotNull(service);
                testService = Assert.IsType <TestActorService>(service);

                Assert.Same(stateManagerFactoryMock, testService.StateManagerFactory);
                Assert.Same(actorFactoryMock, testService.ActorFactory);
                Assert.Same(stateProviderMock.Object, testService.StateProvider);
                Assert.Same(settings, testService.Settings);
                Assert.Same(typeInfo, testService.ActorTypeInfo);
                Assert.Same(context, testService.Context);
            }
        }
Example #2
0
 public PersonActorService(StatefulServiceContext context, ActorTypeInformation actorTypeInfo, Func <ActorService, ActorId, ActorBase> actorFactory = null,
                           Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null, IActorStateProvider stateProvider = null,
                           ActorServiceSettings settings = null) : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     _serviceLoggerFactory       = () => new ServiceDomainLogger(this, ServiceRequestContext.Current);
     _communicationLoggerFactory = () => new CommunicationLogger(this);
 }
        RegisterActor <TActor>(
            this ContainerBuilder builder,
            Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
            IActorStateProvider stateProvider = null,
            ActorServiceSettings settings     = null)
            where TActor : ActorBase
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var actorType = typeof(TActor);

            if (!actorType.CanBeProxied())
            {
                throw new ArgumentException(actorType.GetInvalidProxyTypeErrorMessage());
            }

            var registration = builder.RegisterServiceWithInterception <TActor, ActorInterceptor>();

            registration.EnsureRegistrationIsInstancePerLifetimeScope();

            var creator = new ServiceFabricRegistrationCreator(c => c.Resolve <IActorFactoryRegistration>().RegisterActorFactory <TActor>(
                                                                   c, stateManagerFactory, stateProvider, settings));

            builder.RegisterInstance(creator)
            .As <IServiceFabricRegistrationCreator>();

            // builder.RegisterBuildCallback(
            //    c => c.Resolve<IActorFactoryRegistration>().RegisterActorFactory<TActor>(
            //        c, stateManagerFactory, stateProvider, settings));
            return(registration);
        }
        public MockActorService(
            ICodePackageActivationContext codePackageActivationContext,
            IServiceProxyFactory serviceProxyFactory,
            IActorProxyFactory actorProxyFactory,
            NodeContext nodeContext,
            StatefulServiceContext statefulServiceContext,
            ActorTypeInformation actorTypeInfo,
            Func <ActorService, ActorId, ActorBase> actorFactory = null,
            Func <ActorBase, IActorStateProvider,
                  IActorStateManager> stateManagerFactory = null,
            IActorStateProvider stateProvider             = null,
            ActorServiceSettings settings = null

            ) :
            base(
                context: statefulServiceContext,
                actorTypeInfo: actorTypeInfo,
                actorFactory: actorFactory,
                stateManagerFactory: stateManagerFactory,
                stateProvider: stateProvider,
                settings: settings)
        {
            _codePackageActivationContext = codePackageActivationContext;
            _serviceProxyFactory          = serviceProxyFactory;
            _actorProxyFactory            = actorProxyFactory;
            _nodeContext = nodeContext;
        }
Example #5
0
 public void RegisterActorFactory <TActor>(
     ILifetimeScope container,
     Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
     IActorStateProvider stateProvider = null,
     ActorServiceSettings settings     = null) where TActor : ActorBase
 {
     ActorRuntime.RegisterActorAsync <TActor>((context, actorTypeInfo) =>
     {
         return(new ActorService(context, actorTypeInfo, (actorService, actorId) =>
         {
             var lifetimeScope = container.BeginLifetimeScope(builder =>
             {
                 builder.RegisterInstance(context)
                 .As <StatefulServiceContext>()
                 .As <ServiceContext>();
                 builder.RegisterInstance(actorService)
                 .As <ActorService>();
                 builder.RegisterInstance(actorId)
                 .As <ActorId>();
             });
             var actor = lifetimeScope.Resolve <TActor>();
             return actor;
         }, stateManagerFactory, stateProvider, settings));
     }).GetAwaiter().GetResult();
 }
Example #6
0
 public TestObservableObserverActorService(StatefulServiceContext context,
                                           ActorTypeInformation actorTypeInfo,
                                           Func <ActorBase> actorFactory     = null,
                                           IActorStateProvider stateProvider = null,
                                           ActorServiceSettings settings     = null)
     : base(context, actorTypeInfo, actorFactory, stateProvider, settings)
 {
 }
        public DeviceActorService(
            StatefulServiceContext context,
            ActorTypeInformation typeInfo,
            Func <ActorBase> actorFactory     = null,
            IActorStateProvider stateProvider = null,
            ActorServiceSettings settings     = null)
            : base(context, typeInfo, actorFactory, stateProvider, settings)
        {
            // Read settings from the DeviceActorServiceConfig section in the Settings.xml file
            ICodePackageActivationContext activationContext = context.CodePackageActivationContext;
            ConfigurationPackage          config            = activationContext.GetConfigurationPackageObject(ConfigurationPackage);
            ConfigurationSection          section           = config.Settings.Sections[ConfigurationSection];

            // Read the ServiceBusConnectionString setting from the Settings.xml file
            ConfigurationProperty parameter = section.Parameters[ServiceBusConnectionStringParameter];

            if (!string.IsNullOrWhiteSpace(parameter?.Value))
            {
                this.ServiceBusConnectionString = parameter.Value;
            }
            else
            {
                throw new ArgumentException(
                          string.Format(ParameterCannotBeNullFormat, ServiceBusConnectionStringParameter),
                          ServiceBusConnectionStringParameter);
            }

            // Read the EventHubName setting from the Settings.xml file
            parameter = section.Parameters[EventHubNameParameter];
            if (!string.IsNullOrWhiteSpace(parameter?.Value))
            {
                this.EventHubName = parameter.Value;
            }
            else
            {
                throw new ArgumentException(
                          string.Format(ParameterCannotBeNullFormat, EventHubNameParameter),
                          EventHubNameParameter);
            }

            // Read the QueueLength setting from the Settings.xml file
            parameter = section.Parameters[QueueLengthParameter];
            if (!string.IsNullOrWhiteSpace(parameter?.Value))
            {
                this.QueueLength = DefaultQueueLength;
                int queueLength;
                if (int.TryParse(parameter.Value, out queueLength))
                {
                    this.QueueLength = queueLength;
                }
            }
            else
            {
                throw new ArgumentException(
                          string.Format(ParameterCannotBeNullFormat, QueueLengthParameter),
                          QueueLengthParameter);
            }
        }
 public ActorDemoActorService(
     StatefulServiceContext context,
     ActorTypeInformation actorTypeInfo,
     Func <ActorService, ActorId, Actors.Runtime.ActorBase> actorFactory = null,
     Func <Microsoft.ServiceFabric.Actors.Runtime.ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
     IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) :
     base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
 }
Example #9
0
 protected ObservableObserverActorServiceBase(StatefulServiceContext context,
                                              ActorTypeInformation actorTypeInfo,
                                              Func <ActorBase> actorFactory     = null,
                                              IActorStateProvider stateProvider = null,
                                              ActorServiceSettings settings     = null)
     : base(context, actorTypeInfo, actorFactory, stateProvider, settings)
 {
     ConfigurationHelper.Initialize(this.Context);
 }
Example #10
0
 public ActorBaseService(
     StatefulServiceContext context,
     ActorTypeInformation actorTypeInfo,
     Func <ActorService, ActorId, ActorBase> actorFactory,
     Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
     IActorStateProvider stateProvider = null,
     ActorServiceSettings settings     = null) : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
 }
 public NodeManagerService(
     StatefulServiceContext context,
     ActorTypeInformation actorTypeInfo,
     Func <ActorService, ActorId, ActorBase> actorFactory = null,
     Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
     IActorStateProvider stateProvider = null, ActorServiceSettings settings = null)
     : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     this.nodeManagerSettings = new NodeManagerSettings(context.CodePackageActivationContext.GetConfigurationPackageObject(this.configurationPackageName).Settings);
 }
Example #12
0
 public CommonActorService(StatefulServiceContext context, ActorTypeInformation actorTypeInfo,
                           ILoggerFactory loggerFactory,
                           LoggerConfiguration loggerConfiguration = null,
                           Func <ActorService, ActorId, ActorBase> actorFactory = null,
                           Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
                           IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) : base(context,
                                                                                                                  actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     Logger = loggerFactory.CreateLogger(GetType());
 }
 public ActorServiceEapBase(StatefulServiceContext context,
                            ActorTypeInformation actorTypeInfo,
                            DiagnosticPipeline diagnosticPipeline,
                            Func <ActorService, ActorId, ActorBase> actorFactory = null,
                            Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
                            IActorStateProvider stateProvider = null, ActorServiceSettings settings = null)
     : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     CreateSerilog(diagnosticPipeline);
 }
Example #14
0
 public ActorBackendRemotingV1Service(
     StatefulServiceContext context,
     ActorTypeInformation actorTypeInfo,
     Func <ActorService, ActorId, ActorBase> actorFactory = null,
     Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
     IActorStateProvider stateProvider = null,
     ActorServiceSettings settings     = null)
     : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     FabricTelemetryInitializerExtension.SetServiceCallContext(context);
 }
        public DeviceActorService(StatefulServiceContext context, 
                                  ActorTypeInformation typeInfo,
                                  Func<ActorBase> actorFactory = null, 
                                  IActorStateProvider stateProvider = null, 
                                  ActorServiceSettings settings = null)
            : base(context, typeInfo, actorFactory, stateProvider, settings)
        {
            // Read settings from the DeviceActorServiceConfig section in the Settings.xml file
            var activationContext = Context.CodePackageActivationContext;
            var config = activationContext.GetConfigurationPackageObject(ConfigurationPackage);
            var section = config.Settings.Sections[ConfigurationSection];

            // Read the ServiceBusConnectionString setting from the Settings.xml file
            var parameter = section.Parameters[ServiceBusConnectionStringParameter];
            if (!string.IsNullOrWhiteSpace(parameter?.Value))
            {
                ServiceBusConnectionString = parameter.Value;
            }
            else
            {
                throw new ArgumentException(
                    string.Format(ParameterCannotBeNullFormat, ServiceBusConnectionStringParameter),
                                  ServiceBusConnectionStringParameter);
            }

            // Read the EventHubName setting from the Settings.xml file
            parameter = section.Parameters[EventHubNameParameter];
            if (!string.IsNullOrWhiteSpace(parameter?.Value))
            {
                EventHubName = parameter.Value;
            }
            else
            {
                throw new ArgumentException(string.Format(ParameterCannotBeNullFormat, EventHubNameParameter),
                                            EventHubNameParameter);
            }

            // Read the QueueLength setting from the Settings.xml file
            parameter = section.Parameters[QueueLengthParameter];
            if (!string.IsNullOrWhiteSpace(parameter?.Value))
            {
                QueueLength = DefaultQueueLength;
                int queueLength;
                if (int.TryParse(parameter.Value, out queueLength))
                {
                    QueueLength = queueLength;
                }
            }
            else
            {
                throw new ArgumentException(string.Format(ParameterCannotBeNullFormat, QueueLengthParameter),
                                            QueueLengthParameter);
            }
        }
        public void RegisterActorFactory <TActor>(
            ILifetimeScope container,
            Type actorServiceType,
            Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
            IActorStateProvider stateProvider     = null,
            ActorServiceSettings settings         = null,
            object lifetimeScopeTag               = null,
            Action <ILifetimeScope> scopeCallback = null)
            where TActor : ActorBase
        {
            ActorRuntime.RegisterActorAsync <TActor>((context, actorTypeInfo) =>
            {
                ActorBase ActorFactory(ActorService actorService, ActorId actorId)
                {
                    var tag = lifetimeScopeTag ?? Constants.DefaultLifetimeScopeTag;

                    var lifetimeScope = container.BeginLifetimeScope(tag, builder =>
                    {
                        builder.RegisterInstance(context)
                        .As <StatefulServiceContext>()
                        .As <ServiceContext>();
                        builder.RegisterInstance(actorService)
                        .As <ActorService>();
                        builder.RegisterInstance(actorId)
                        .As <ActorId>();
                    });

                    scopeCallback?.Invoke(lifetimeScope);

                    try
                    {
                        var actor = lifetimeScope.Resolve <TActor>();
                        return(actor);
                    }
                    catch (Exception ex)
                    {
                        // Proactively dispose lifetime scope as interceptor will not be called.
                        lifetimeScope.Dispose();

                        this.ConstructorExceptionCallback(ex);
                        throw;
                    }
                }

                return((ActorService)container.Resolve(
                           actorServiceType,
                           new TypedParameter(typeof(StatefulServiceContext), context),
                           new TypedParameter(typeof(ActorTypeInformation), actorTypeInfo),
                           new TypedParameter(typeof(Func <ActorService, ActorId, ActorBase>), (Func <ActorService, ActorId, ActorBase>)ActorFactory),
                           new TypedParameter(typeof(Func <ActorBase, IActorStateProvider, IActorStateManager>), stateManagerFactory),
                           new TypedParameter(typeof(IStateProvider), stateProvider),
                           new TypedParameter(typeof(ActorServiceSettings), settings)));
            }).GetAwaiter().GetResult();
        }
Example #17
0
 public StudentActorService
 (
     StatefulServiceContext context,
     ActorTypeInformation actorTypeInfo,
     Func <ActorService, ActorId, ActorBase> actorFactory = null,
     Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
     IActorStateProvider stateProvider = null,
     ActorServiceSettings settings     = null) :
     base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     _stateProviderEventStreamReader = new ActorStateProviderEventStreamReader(StateProvider, StudentActor.EventStreamStateKey);
 }
 protected BackupRestoreActorService(StatefulServiceContext context,
                                     ActorTypeInformation actorTypeInfo,
                                     IFileStore fileStore,
                                     IServiceEventSource serviceEventSource, Func <ActorService, ActorId, ActorBase> actorFactory = null,
                                     Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
                                     IActorStateProvider stateProvider = null,
                                     ActorServiceSettings settings     = null)
     : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     this._serviceEventSource = serviceEventSource;
     this._fileStore          = fileStore;
 }
 /// <summary>
 /// Creates a new instance, using the provided arguments.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="actorTypeInfo"></param>
 /// <param name="centralBackupStore"></param>
 /// <param name="logCallback"></param>
 /// <param name="actorFactory"></param>
 /// <param name="stateManagerFactory"></param>
 /// <param name="stateProvider"></param>
 /// <param name="settings"></param>
 protected BackupRestoreActorService(StatefulServiceContext context,
                                     ActorTypeInformation actorTypeInfo,
                                     ICentralBackupStore centralBackupStore,
                                     Action <string> logCallback, Func <ActorService, ActorId, ActorBase> actorFactory = null,
                                     Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory     = null,
                                     IActorStateProvider stateProvider = null,
                                     ActorServiceSettings settings     = null)
     : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     _centralBackupStore = centralBackupStore ?? throw new ArgumentNullException(nameof(centralBackupStore));
     _logCallback        = logCallback;
 }
Example #20
0
 protected EventStoredActorService
     (StatefulServiceContext context,
     ActorTypeInformation actorTypeInfo,
     Func <Microsoft.ServiceFabric.Actors.Runtime.ActorService, ActorId, ActorBase> actorFactory = null,
     Func <Microsoft.ServiceFabric.Actors.Runtime.ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
     IActorStateProvider stateProvider = null,
     ActorServiceSettings settings     = null,
     IReliableStateManagerReplica reliableStateManagerReplica = null,
     IEventStreamReader <TEventStream> eventStreamReader      = null)
     : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings, reliableStateManagerReplica)
 {
     StateProviderEventStreamReader = eventStreamReader ?? new EventStreamReader <TEventStream>(StateProvider, EventStoredActor <TAggregateRoot, TEventStream> .EventStreamStateKey);
 }
Example #21
0
 public ActorService(
     StatefulServiceContext context,
     ActorTypeInformation actorTypeInfo,
     Func <Microsoft.ServiceFabric.Actors.Runtime.ActorService, ActorId, ActorBase> actorFactory = null,
     Func <Microsoft.ServiceFabric.Actors.Runtime.ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
     IActorStateProvider stateProvider = null,
     ActorServiceSettings settings     = null,
     IReliableStateManagerReplica reliableStateManagerReplica = null) :
     base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     StateManager = reliableStateManagerReplica ??
                    (IReliableStateManagerReplica) new ReliableStateManager(context, (ReliableStateManagerConfiguration)null);
 }
Example #22
0
 public Actor1Service(StatefulServiceContext context, ActorTypeInformation actorTypeInfo,
                      Func <ActorService, ActorId, ActorBase> actorFactory = null,
                      Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
                      IActorStateProvider stateProvider = null, ActorServiceSettings settings = null)
     : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     _connectionString = context
                         .CodePackageActivationContext
                         .GetConfigurationPackageObject("Config")
                         .Settings
                         .Sections["BusConfig"]
                         .Parameters["AzureServiceBusConnectionString"].Value;
 }
Example #23
0
 public DefaultFtpActionService(StatefulServiceContext context, ActorTypeInformation actorTypeInfo,
                                ILoggerFactory loggerFactory,
                                string scalerActorServiceName,
                                string scalerActorId,
                                LoggerConfiguration loggerConfiguration = null,
                                Func <ActorService, ActorId, ActorBase> actorFactory = null,
                                Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
                                IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) : base(context,
                                                                                                                       actorTypeInfo, loggerFactory, loggerConfiguration, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     _scalerActorServiceName = scalerActorServiceName;
     _scalerActorId          = scalerActorId;
 }
Example #24
0
        public void RegisterActorCanBeCalledWithSettings()
        {
            var builder  = new ContainerBuilder();
            var settings = new ActorServiceSettings();

            builder.RegisterActor <Actor1>(settings: settings);
            var factoryMock = new Mock <IActorFactoryRegistration>();

            builder.RegisterInstance(factoryMock.Object);

            var container = builder.Build();

            container.AssertRegistered <Actor1>();
            factoryMock.Verify(x => x.RegisterActorFactory <Actor1>(container, typeof(ActorService), null, null, settings, null), Times.Once);
        }
Example #25
0
 public FtpSchedulerActorService(StatefulServiceContext context,
                                 ActorTypeInformation actorTypeInfo,
                                 ILoggerFactory loggerFactory,
                                 IServiceConfiguration serviceConfiguration,
                                 string schedulerActorServiceName,
                                 string sectionKeyName = null,
                                 LoggerConfiguration loggerConfiguration = null,
                                 Func <ActorService, ActorId, ActorBase> actorFactory = null,
                                 Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
                                 IActorStateProvider stateProvider = null,
                                 ActorServiceSettings settings     = null) : base(context, actorTypeInfo, loggerFactory, loggerConfiguration, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     ServiceConfiguration      = serviceConfiguration;
     SectionKeyName            = sectionKeyName ?? this.GetType().Name;
     SchedulerActorServiceName = schedulerActorServiceName;
 }
Example #26
0
 public DelegatedActorService(
     StatefulServiceContext context,
     ActorTypeInformation actorTypeInfo,
     Action <IServiceCollection> configureServices,
     Func <ActorService, ActorId, IServiceScopeFactory, Action <IServiceProvider>, ActorBase> actorFactory,
     ActorServiceSettings settings = null) : base(
         context,
         actorTypeInfo,
         ActorFactory,
         null,
         new KvsActorStateProvider(),
         settings)
 {
     _configureServices = configureServices;
     _actorFactory      = actorFactory;
 }
        RegisterActor <TActor>(
            this ContainerBuilder builder,
            Type actorServiceType = null,
            Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
            IActorStateProvider stateProvider     = null,
            ActorServiceSettings settings         = null,
            object lifetimeScopeTag               = null,
            Action <ILifetimeScope> scopeCallback = null)
            where TActor : ActorBase
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var actorType = typeof(TActor);

            if (!actorType.CanBeProxied())
            {
                throw new ArgumentException(actorType.GetInvalidProxyTypeErrorMessage());
            }

            if (actorServiceType == null)
            {
                actorServiceType = typeof(ActorService);
            }
            else
            {
                builder.RegisterType(actorServiceType).AsSelf().IfNotRegistered(actorServiceType);
            }

            if (!typeof(ActorService).IsAssignableFrom(actorServiceType))
            {
                throw new ArgumentException(actorServiceType.GetInvalidActorServiceTypeErrorMessage());
            }

            var registration = builder.RegisterServiceWithInterception <TActor, ActorInterceptor>(lifetimeScopeTag);

            registration.EnsureRegistrationIsInstancePerLifetimeScope();

            builder.RegisterBuildCallback(
                c => c.Resolve <IActorFactoryRegistration>().RegisterActorFactory <TActor>(
                    c, actorServiceType, stateManagerFactory, stateProvider, settings, lifetimeScopeTag, scopeCallback));

            return(registration);
        }
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="actorTypeInfo"></param>
 /// <param name="fabric"></param>
 /// <param name="logger"></param>
 /// <param name="actorFactory"></param>
 /// <param name="stateManagerFactory"></param>
 /// <param name="stateProvider"></param>
 /// <param name="settings"></param>
 public MonitorActorService(
     StatefulServiceContext context,
     ActorTypeInformation actorTypeInfo,
     FabricClient fabric,
     ILogger logger,
     Func <ActorService, ActorId, ActorBase> actorFactory = null,
     Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
     IActorStateProvider stateProvider = null,
     ActorServiceSettings settings     = null) : base(
         context,
         actorTypeInfo,
         actorFactory,
         stateManagerFactory,
         stateProvider,
         settings)
 {
     this.fabric = fabric ?? throw new ArgumentNullException(nameof(fabric));
     this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Example #29
0
        public WorkerActorService(StatefulServiceContext context,
                                  ActorTypeInformation typeInfo,
                                  Func <ActorService, ActorId, ActorBase> actorFactory,
                                  Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory,
                                  IActorStateProvider stateProvider = null,
                                  ActorServiceSettings settings     = null)
            : base(context, typeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
        {
            // Read Settings
            ReadSettings(context.CodePackageActivationContext.GetConfigurationPackageObject(ConfigurationPackage));

            // Creates event handlers for configuration changes
            context.CodePackageActivationContext.ConfigurationPackageAddedEvent +=
                CodePackageActivationContext_ConfigurationPackageAddedEvent;
            context.CodePackageActivationContext.ConfigurationPackageModifiedEvent +=
                CodePackageActivationContext_ConfigurationPackageModifiedEvent;
            context.CodePackageActivationContext.ConfigurationPackageRemovedEvent +=
                CodePackageActivationContext_ConfigurationPackageRemovedEvent;
        }
Example #30
0
 public TheActorService(StatefulServiceContext context,
                        ActorTypeInformation actorTypeInfo,
                        DiagnosticPipeline diagnosticPipeline,
                        IBusControl bus = null,
                        Func <ActorService, ActorId, ActorBase> actorFactory = null,
                        Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
                        IActorStateProvider stateProvider = null,
                        ActorServiceSettings settings     = null)
     : base(context, actorTypeInfo, diagnosticPipeline, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     if (bus == null)
     {
         EventBus = CreateBus();
     }
     else
     {
         EventBus = bus;
     }
 }
 public TransactionActorService(
     StatefulServiceContext context,
     ActorTypeInformation actorTypeInfo,
     Func <TransactionActorService, ActorId, IDeleteActor, TransactionManager> actorFactory = null,
     Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory          = null,
     IActorStateProvider stateProvider = null,
     ActorServiceSettings settings     = null)
     : base(
         context,
         actorTypeInfo,
         (service, id) =>
 {
     var actorService = (TransactionActorService)service;
     return(actorFactory?.Invoke(actorService, id, actorService.DeleteActorService));
 },
         stateManagerFactory,
         stateProvider,
         settings)
 {
     this.transactionManagerActorGarbageCollector = new TransactionManagerActorGarbageCollector(this.StateProvider, TimeSpan.FromSeconds(10), CancellationToken.None);
 }
 public TelemetryEnabledActorService(StatefulServiceContext context, ActorTypeInformation actorTypeInfo, Func<ActorBase> actorFactory = null, IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) : base(context, actorTypeInfo, actorFactory, stateProvider, settings)
 {}