private static ContainerBuilder ConfigureBuilderDependencies()
        {
            var builder = new ContainerBuilder();

//            builder.RegisterType<PostcodeFactorsReferenceDataContext>().As<IPostcodeFactorsReferenceDataContext>().InstancePerMatchingLifetimeScope("childLifeTimeScope");
//            builder.RegisterType<LarsContext>().As<ILarsContext>().InstancePerMatchingLifetimeScope("childLifeTimeScope");
//            builder.RegisterType<ReferenceDataCache>().As<IReferenceDataCache>().InstancePerMatchingLifetimeScope("childLifeTimeScope");
//            builder.RegisterType<OpaService>().As<IOpaService>().InstancePerMatchingLifetimeScope("childLifeTimeScope");
//            builder.RegisterType<DataPersisterConfig>().As<IDataPersisterConfig>().InstancePerMatchingLifetimeScope("childLifeTimeScope");
//            builder.RegisterType<DataPersister>().As<IDataPersister>().InstancePerMatchingLifetimeScope("childLifeTimeScope");
//            builder.RegisterType<FundingServiceConfigSF>().As<IFundingServiceConfig>().InstancePerMatchingLifetimeScope("childLifeTimeScope");
//            builder.RegisterType<AttributeListBuilder>().As<IAttributeListBuilder<AttributeData>>().InstancePerMatchingLifetimeScope("childLifeTimeScope");
//            builder.RegisterType<FundingService.Service.Implementation.FundingService>().As<IFundingService>().InstancePerMatchingLifetimeScope("childLifeTimeScope");

            builder.RegisterType <PostcodeFactorsReferenceDataContext>().As <IPostcodeFactorsReferenceDataContext>().InstancePerLifetimeScope();
            builder.RegisterType <LarsContext>().As <ILarsContext>().InstancePerLifetimeScope();
            builder.RegisterType <ReferenceDataCacheSF>().As <IReferenceDataCache>().InstancePerLifetimeScope();
            builder.RegisterType <OpaService>().As <IOpaService>().InstancePerLifetimeScope();
            builder.RegisterType <DataPersisterConfig>().As <IDataPersisterConfig>().InstancePerLifetimeScope();
            builder.RegisterType <DataPersister>().As <IDataPersister>().InstancePerLifetimeScope();
            builder.RegisterType <FundingServiceConfigSF>().As <IFundingServiceConfig>().InstancePerLifetimeScope();
            builder.RegisterType <AttributeListBuilder>().As <IAttributeListBuilder <AttributeData> >().InstancePerLifetimeScope();
            builder.RegisterType <FundingService.Service.Implementation.FundingService>().As <IFundingService>()
            .InstancePerLifetimeScope();


            var config = new ESFA.DC.Logging.ApplicationLoggerSettings();

            config.LoggerOutput = ESFA.DC.Logging.Enums.LogOutputDestination.SqlServer;
            builder.RegisterType <ESFA.DC.Logging.SeriLogging.SeriLogger>().As <ESFA.DC.Logging.ILogger>()
            .WithParameter(new TypedParameter(typeof(ESFA.DC.Logging.ApplicationLoggerSettings), config))
            .InstancePerLifetimeScope();

            return(builder);
        }
Пример #2
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                // This line registers an Actor Service to host your actor class with the Service Fabric runtime.
                // The contents of your ServiceManifest.xml and ApplicationManifest.xml files
                // are automatically populated when you build this project.
                // For more information, see https://aka.ms/servicefabricactorsplatform
                // **** Instantiate log collection via EventFlow
                using (var diagnosticsPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("DCT.ILR.ValidationService.LearnerActor-pipeline"))
                {
                    // Start with the trusty old container builder.
                    var builder = new ContainerBuilder();

                    // Register any regular dependencies.
                    //builder.RegisterModule(new LoggerModule(ActorEventSource.Current.Message));
                    builder.RegisterModule <BusinessLogicAutofacModule>();
                    builder.RegisterModule <ValidationServiceServiceModuleSF>();

                    var config = new ESFA.DC.Logging.ApplicationLoggerSettings();
                    config.LoggerOutput = ESFA.DC.Logging.Enums.LogOutputDestination.SqlServer;
                    builder.RegisterType <ESFA.DC.Logging.SeriLogging.SeriLogger>().As <ESFA.DC.Logging.ILogger>()
                    .WithParameter(new TypedParameter(typeof(ESFA.DC.Logging.ApplicationLoggerSettings), config))
                    .InstancePerLifetimeScope();

                    builder.RegisterType <RuleManager>().As <IRuleManager>();
                    builder.RegisterType <RuleManagerValidationService>().As <IValidationService>().InstancePerLifetimeScope();


                    // Register the Autofac magic for Service Fabric support.
                    builder.RegisterServiceFabricSupport();

                    // Register the actor service.
                    builder.RegisterActor <LearnerActor>();

                    using (var container = builder.Build())
                    {
                        using (var childscope = container.BeginLifetimeScope())
                        {
                            var val = childscope.Resolve <IValidationService>();
                        }
                        Thread.Sleep(Timeout.Infinite);
                    }
                }

                // ActorRuntime.RegisterActorAsync<LearnerActor>(
                //(context, actorType) => new ActorService(context, actorType)).GetAwaiter().GetResult();
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
Пример #3
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                // The ServiceManifest.XML file defines one or more service type names.
                // Registering a service maps a service type name to a .NET type.
                // When Service Fabric creates an instance of this service type,
                // an instance of the class is created in this host process.

                // Start with the trusty old container builder.
                var builder = new ContainerBuilder();

                // Register any regular dependencies.


                var config = new ESFA.DC.Logging.ApplicationLoggerSettings();
                config.LoggerOutput = ESFA.DC.Logging.Enums.LogOutputDestination.SqlServer;
                builder.RegisterType <ESFA.DC.Logging.SeriLogging.SeriLogger>().As <ESFA.DC.Logging.ILogger>()
                .WithParameter(new TypedParameter(typeof(ESFA.DC.Logging.ApplicationLoggerSettings), config))
                .InstancePerLifetimeScope();

                //get the config values and register in container
                var fundingActorOptions =
                    ConfigurationHelper.GetSectionValues <ActorOptions>("FundingActorsSection");
                builder.RegisterInstance(fundingActorOptions).As <ActorOptions>().SingleInstance();

                var dataServiceOptions =
                    ConfigurationHelper.GetSectionValues <DataServiceOptions>("DataServiceSection");
                builder.RegisterInstance(dataServiceOptions).As <DataServiceOptions>().SingleInstance();

                builder.RegisterInstance(new ActorsHelper()).As <IActorsHelper>();


                //store proxy factory in container
                var serviceProxyFactory = new ServiceProxyFactory(
                    (c) => new FabricTransportServiceRemotingClientFactory(
                        remotingSettings: FabricTransportRemotingSettings.LoadFrom("DataTransportSettings"),
                        remotingCallbackMessageHandler: null, servicePartitionResolver: null, exceptionHandlers: null,
                        traceId: null,
                        serializationProvider: new ServiceRemotingJsonSerializationProvider()));

                builder.RegisterInstance(serviceProxyFactory).As <ServiceProxyFactory>().SingleInstance();

                builder.RegisterType <FundingCalcManager>().As <IFundingCalcManager>().InstancePerLifetimeScope();


                // Register the Autofac magic for Service Fabric support.
                builder.RegisterServiceFabricSupport();
                // Register the stateless service.
                builder.RegisterStatelessService <FundingCalcService>("DCT.ILR.FundingCalcServiceType");

                builder.Register(c =>
                {
                    var ctx = c.Resolve <StatelessServiceContext>();
                    return(ctx.CodePackageActivationContext.ApplicationName);
                }).Named <string>("ApplicationName");

                //ServiceRuntime.RegisterServiceAsync("DCT.ILR.VadationServiceStatefulType",
                //    context => new VadationServiceStateful(context)).GetAwaiter().GetResult();

                //ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(VadationServiceStateful).Name);

                using (var container = builder.Build())
                {
                    using (var childlifetime = container.BeginLifetimeScope())
                    {
                        var s = childlifetime.Resolve <IFundingCalcManager>();
                    }

                    //var logger = container.Resolve<ESFA.DC.Logging.ILogger>();
                    ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(FundingCalcService).Name);

                    // Prevents this host process from terminating so services keep running.
                    Thread.Sleep(Timeout.Infinite);
                }
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
                throw;
            }
        }
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                // The ServiceManifest.XML file defines one or more service type names.
                // Registering a service maps a service type name to a .NET type.
                // When Service Fabric creates an instance of this service type,
                // an instance of the class is created in this host process.

                using (var diagnosticsPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("DCT.ILR.ValidationServiceStateless-pipeline"))
                {
                    // Start with the trusty old container builder.
                    var builder = new ContainerBuilder();

                    // Register any regular dependencies.
                    builder.RegisterModule <BusinessLogicAutofacModule>();
                    builder.RegisterModule <ValidationServiceServiceModuleSF>();

                    var config = new ESFA.DC.Logging.ApplicationLoggerSettings();
                    config.LoggerOutput = ESFA.DC.Logging.Enums.LogOutputDestination.SqlServer;
                    builder.RegisterType <ESFA.DC.Logging.SeriLogging.SeriLogger>().As <ESFA.DC.Logging.ILogger>()
                    .WithParameter(new TypedParameter(typeof(ESFA.DC.Logging.ApplicationLoggerSettings), config))
                    .InstancePerLifetimeScope();


                    var applicationInsightsKey = FabricRuntime.GetActivationContext()
                                                 .GetConfigurationPackageObject("Config")
                                                 .Settings
                                                 .Sections["ConfigurationSection"]
                                                 .Parameters["ApplicationInsightsKey"]
                                                 .Value;

                    var configurationOptions =
                        ConfigurationHelper.GetSectionValues <ConfigurationOptions>("ConfigurationSection");

                    var seviceBusOptions =
                        ConfigurationHelper.GetSectionValues <ServiceBusOptions>("ServiceBusSettings");


                    builder.RegisterInstance(configurationOptions).As <ConfigurationOptions>().SingleInstance();
                    builder.RegisterInstance(seviceBusOptions).As <ServiceBusOptions>().SingleInstance();



                    //var loggerFactory = new LoggerFactoryBuilder().CreateLoggerFactory(applicationInsightsKey);
                    //logger = loggerFactory.CreateLogger<MyStateless>();

                    builder.RegisterType <TopicHelper>().As <ITopicHelper>().InstancePerDependency();
                    builder.RegisterType <RuleManager>().As <IRuleManager>();
                    //builder.Register(c =>
                    //        new RuleManagerValidationService(c.Resolve<IRuleManager>(), c.Resolve<IFileData>()))
                    //    .As<IValidationService>().InstancePerLifetimeScope();
                    builder.RegisterType <RuleManagerValidationService>().As <IValidationService>().InstancePerLifetimeScope();

                    builder.RegisterInstance(new ActorsHelper()).As <IActorsHelper>();

                    // Register the Autofac magic for Service Fabric support.
                    builder.RegisterServiceFabricSupport();
                    // Register the stateless service.
                    builder.RegisterStatelessService <ValidationServiceStateless>("DCT.ILR.ValidationServiceStatelessType");

                    //ServiceRuntime.RegisterServiceAsync("DCT.ILR.VadationServiceStatefulType",
                    //    context => new VadationServiceStateful(context)).GetAwaiter().GetResult();

                    //ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(VadationServiceStateful).Name);

                    using (var container = builder.Build())
                    {
                        using (var newScope = container.BeginLifetimeScope())
                        {
                            var val = newScope.Resolve <IValidationService>();
                        }
                        ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(ValidationServiceStateless).Name);

                        // Prevents this host process from terminating so services keep running.
                        Thread.Sleep(Timeout.Infinite);
                    }
                }
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
                throw;
            }
        }