コード例 #1
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            var config = builder.GetBeefConfiguration <Startup>("Beef_");

            // Add the core beef services.
            builder.Services.AddBeefExecutionContext()
            .AddBeefRequestCache()
            .AddBeefCachePolicyManager(config.GetSection("BeefCaching").Get <CachePolicyConfig>())
            .AddBeefBusinessServices();

            // Add event subscriber host and auto-discovered subscribers.
            builder.Services.AddBeefEventHubSubscriberHost(EventSubscriberHostArgs.Create <Startup>());

            // Add the data sources as singletons for dependency injection requirements.
            var ccs = config.GetSection("CosmosDb");

            builder.Services.AddScoped <Data.Database.IDatabase>(_ => new Database(config.GetConnectionString("BeefDemo")))
            .AddDbContext <EfDbContext>()
            .AddScoped <Data.EntityFrameworkCore.IEfDb, EfDb>()
            .AddSingleton <Data.Cosmos.ICosmosDb>(_ => new CosmosDb(new Cosmos.CosmosClient(ccs.GetValue <string>("EndPoint"), ccs.GetValue <string>("AuthKey")), ccs.GetValue <string>("Database")));

            // Add the generated reference data services for dependency injection requirements.
            builder.Services.AddGeneratedReferenceDataManagerServices()
            .AddGeneratedReferenceDataDataSvcServices()
            .AddGeneratedReferenceDataDataServices();

            // Add the generated entity services for dependency injection requirements.
            builder.Services.AddGeneratedManagerServices()
            .AddGeneratedDataSvcServices()
            .AddGeneratedDataServices();

            // Add event publishing.
            builder.Services.AddBeefEventHubEventPublisher(config.GetValue <string>("EventHubConnectionString"));
        }
コード例 #2
0
        public void Ctor_SubscribersInAssembly()
        {
            var args = EventSubscriberHostArgs.Create(GetType().Assembly);
            var ts   = args.GetSubscriberTypes();

            Assert.AreEqual(2, ts.Length);
        }
コード例 #3
0
        public void Ctor_NoIEventSubscriber()
        {
            var sp = TestSetUp.CreateServiceProvider();

            ExpectException.Throws <ArgumentException>("*", () => EventSubscriberHostArgs.Create(sp));
            ExpectException.Throws <ArgumentException>("*", () => EventSubscriberHostArgs.Create(sp, (Type[])null));
            ExpectException.Throws <ArgumentException>("*", () => EventSubscriberHostArgs.Create(sp, new Type[] { }));
        }
コード例 #4
0
ファイル: Startup.cs プロジェクト: ostat/Beef
 public override void Configure(IFunctionsHostBuilder builder)
 {
     // Services configuration as follows:
     // - .AddBeefExecutionContext - enables the `ExecutionContext` required internally by _Beef_.
     // - .AddBeefServiceBusReceiverHost - adds the capability to encapsulate the receive orchestration Azure Service Bus messages.
     builder.Services.AddBeefExecutionContext();
     builder.Services.AddBeefServiceBusReceiverHost(EventSubscriberHostArgs.Create <Startup>());
 }
コード例 #5
0
        public void C120_DoNotAllowMultipleMessages()
        {
            var sp = TestSetUp.CreateServiceProvider();

            ExpectException.Throws<EventSubscriberException>(
                "The 'EventDataSubscriberHost' does not AllowMultipleMessages; there were 2 event messages.",
                async () => await new EventDataSubscriberHost(EventSubscriberHostArgs.Create(typeof(TestSub)).UseServiceProvider(sp).UseLoggerForAuditing()).ReceiveAsync(new EventData(), new EventData()));
        }
コード例 #6
0
        public void Ctor_SubscribersInAssembly()
        {
            var args = new EventSubscriberHostArgs(TestSetUp.CreateLogger(), this.GetType().Assembly);

            Assert.AreEqual(2, args.EventSubscribers.Count());

            args = new EventSubscriberHostArgs(TestSetUp.CreateLogger());
            Assert.AreEqual(2, args.EventSubscribers.Count());
        }
コード例 #7
0
        public void C110_TooManySubjectSubscribers()
        {
            var ed = new EventData<string> { Subject = "Test.Blah.123", Action = "CREATE", Username = "******", Value = "TEST" };
            var sp = TestSetUp.CreateServiceProvider();

            ExpectException.Throws<EventSubscriberException>(
                "There are 2 IEventSubscriber instances subscribing to Subject 'Test.Blah.123' and Action 'CREATE'; there must be only a single subscriber.",
                async () => await new EventDataSubscriberHost(EventSubscriberHostArgs.Create(typeof(TestSub), typeof(TestSubS)).UseServiceProvider(sp).UseLoggerForAuditing()).ReceiveAsync(ed));
        }
コード例 #8
0
        public async Task C130_AllowMultipleMessages()
        {
            var sp = TestSetUp.CreateServiceProvider();

            await new EventDataSubscriberHost(EventSubscriberHostArgs.Create(sp, typeof(TestSub)).UseLoggerForAuditing()).AllowMultipleMessages().ReceiveAsync(new EventData {
                Subject = "X"
            }, new EventData {
                Subject = "X"
            });
        }
コード例 #9
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            var config = builder.GetBeefConfiguration <Startup>("Beef_");

            // Add the core beef services.
            builder.Services.AddBeefExecutionContext()
            .AddBeefSystemTime()
            .AddBeefRequestCache()
            .AddBeefCachePolicyManager(config.GetSection("BeefCaching").Get <CachePolicyConfig>(), new System.TimeSpan(0, 0, 30), new System.TimeSpan(0, 0, 30), useCachePolicyManagerTimer: true)
            .AddBeefBusinessServices();

            // Add event subscriber host with auto-discovered subscribers and set the audit writer to use azure storage; plus use the poison event orchestrator/invoker.
            var ehasr = new EventHubAzureStorageRepository(config.GetConnectionString("AzureStorage"));

            builder.Services.AddBeefEventHubConsumerHost(
                EventSubscriberHostArgs.Create <Startup>().UseAuditWriter(ehasr).UseMaxAttempts(10), additional: (_, ehsh) => ehsh.UseInvoker(new EventHubConsumerHostPoisonInvoker(ehasr)));

            var sbasr = new ServiceBusAzureStorageRepository(config.GetConnectionString("AzureStorage"));

            builder.Services.AddBeefServiceBusReceiverHost(
                EventSubscriberHostArgs.Create <Startup>().UseAuditWriter(sbasr).UseMaxAttempts(10), additional: (_, ehsh) => ehsh.UseInvoker(new ServiceBusReceiverHostPoisonInvoker(sbasr)));

            // Add the data sources as singletons for dependency injection requirements.
            var ccs = config.GetSection("CosmosDb");

            builder.Services.AddScoped <Data.Database.IDatabase>(_ => new Database(config.GetConnectionString("BeefDemo")))
            .AddDbContext <EfDbContext>()
            .AddScoped <Data.EntityFrameworkCore.IEfDb, EfDb>()
            .AddSingleton <Data.Cosmos.ICosmosDb>(_ => new CosmosDb(new Cosmos.CosmosClient(ccs.GetValue <string>("EndPoint"), ccs.GetValue <string>("AuthKey")), ccs.GetValue <string>("Database")));

            // Add the generated reference data services for dependency injection requirements.
            builder.Services.AddGeneratedReferenceDataManagerServices()
            .AddGeneratedReferenceDataDataSvcServices()
            .AddGeneratedReferenceDataDataServices();

            // Add the generated entity services for dependency injection requirements.
            builder.Services.AddGeneratedManagerServices()
            .AddGeneratedValidationServices()
            .AddGeneratedDataSvcServices()
            .AddGeneratedDataServices();

            // Add identifier generator services.
            builder.Services.AddSingleton <IGuidIdentifierGenerator, GuidIdentifierGenerator>()
            .AddSingleton <IStringIdentifierGenerator, StringIdentifierGenerator>();

            // Add event publishing.
            builder.Services.AddBeefEventHubEventProducer(new EventHubProducerClient(config.GetValue <string>("EventHubConnectionString")));

            // Add the AutoMapper profiles.
            builder.Services.AddAutoMapper(Mapper.AutoMapperProfile.Assembly, typeof(ContactData).Assembly);

            // Add logging.
            builder.Services.AddLogging();
        }
コード例 #10
0
 public void Ctor_NoSubscribersInAssembly()
 {
     ExpectException.Throws <ArgumentException>("*", () => EventSubscriberHostArgs.Create(typeof(TestAttribute).Assembly));
 }
コード例 #11
0
 public void Ctor_NoIEventSubscriber()
 {
     ExpectException.Throws <ArgumentException>("*", () => EventSubscriberHostArgs.Create());
     ExpectException.Throws <ArgumentException>("*", () => EventSubscriberHostArgs.Create((Type[])null));
     ExpectException.Throws <ArgumentException>("*", () => EventSubscriberHostArgs.Create(new Type[] { }));
 }
コード例 #12
0
ファイル: EventSubscriberHost.cs プロジェクト: ostat/Beef
 /// <summary>
 /// Initializes a new instance of the <see cref="EventSubscriberHost"/>.
 /// </summary>
 /// <param name="args">The <see cref="EventSubscriberHostArgs"/>.</param>
 protected EventSubscriberHost(EventSubscriberHostArgs args) => Args = Check.NotNull(args, nameof(args));
コード例 #13
0
 private EventDataSubscriberHost CreateTestHost<T>(Func<T> create) where T : class
 {
     var sp = TestSetUp.CreateServiceProvider(sc => sc.AddTransient(_ => create()));
     return new EventDataSubscriberHost(EventSubscriberHostArgs.Create(typeof(T)).UseServiceProvider(sp).UseLoggerForAuditing());
 }
コード例 #14
0
        public void Ctor_NoSubscribersInAssembly()
        {
            var sp = TestSetUp.CreateServiceProvider();

            ExpectException.Throws <ArgumentException>("*", () => EventSubscriberHostArgs.Create(sp, typeof(TestAttribute).Assembly));
        }
コード例 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestEventSubscriberHost"/>.
 /// </summary>
 /// <param name="args">The <see cref="TestEventSubscriberHost"/>.</param>
 internal TestEventSubscriberHost(EventSubscriberHostArgs args) : base(args) => _ec = ExecutionContext.HasCurrent ? ExecutionContext.Current : throw new InvalidOperationException("ExecutionContext.Current must have a value.");
コード例 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventSubscriberTestHost"/>.
 /// </summary>
 /// <param name="args">The <see cref="EventSubscriberTestHost"/>.</param>
 public EventSubscriberTestHost(EventSubscriberHostArgs args) : base(args)
 {
 }
コード例 #17
0
ファイル: EventHubConsumerHost.cs プロジェクト: Avanade/Beef
 /// <summary>
 /// Initializes a new instance of the <see cref="EventHubConsumerHost"/> with the specified <see cref="EventSubscriberHostArgs"/>.
 /// </summary>
 /// <param name="args">The optional <see cref="EventHubConsumerHost"/>.</param>
 /// <param name="eventDataConverter">The optional <see cref="IEventDataConverter{T}"/>. Defaults to a <see cref="EventHubsEventConverter"/> using a <see cref="NewtonsoftJsonCloudEventSerializer"/>.</param>
 public EventHubConsumerHost(EventSubscriberHostArgs args, IEventDataConverter <AzureEventHubs.EventData>?eventDataConverter = null)
     : base(args, eventDataConverter ?? new EventHubsEventConverter(new NewtonsoftJsonCloudEventSerializer()))
 {
 }
コード例 #18
0
ファイル: EventHubExtensions.cs プロジェクト: ostat/Beef
        /// <summary>
        /// Adds a transient service to instantiate a new <see cref="EventHubConsumerHost"/> instance using the specified <paramref name="args"/>.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection"/>.</param>
        /// <param name="args">The <see cref="EventSubscriberHostArgs"/>.</param>
        /// <param name="addSubscriberTypeServices">Indicates whether to add all the <see cref="EventSubscriberHostArgs.GetSubscriberTypes"/> as scoped services (defaults to <c>true</c>).</param>
        /// <param name="additional">Optional (additional) opportunity to further configure the instantiated <see cref="EventHubConsumerHost"/>.</param>
        /// <returns>The <see cref="IServiceCollection"/> for fluent-style method-chaining.</returns>
        public static IServiceCollection AddBeefEventHubConsumerHost(this IServiceCollection services, EventSubscriberHostArgs args, bool addSubscriberTypeServices = true, Action <IServiceProvider, EventHubConsumerHost>?additional = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

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

            services.AddTransient(sp =>
            {
                var ehsh = new EventHubConsumerHost(args);
                args.UseServiceProvider(sp);
                additional?.Invoke(sp, ehsh);
                return(ehsh);
            });

            if (addSubscriberTypeServices)
            {
                foreach (var type in args.GetSubscriberTypes())
                {
                    services.TryAddScoped(type);
                }
            }

            return(services);
        }
コード例 #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceBusReceiverHost"/> with the specified <see cref="EventSubscriberHostArgs"/>.
 /// </summary>
 /// <param name="args">The <see cref="EventSubscriberHostArgs"/>.</param>
 /// <param name="eventDataConverter">The optional <see cref="IEventDataConverter{T}"/>. Defaults to a <see cref="MicrosoftServiceBusMessageConverter"/> using a <see cref="NewtonsoftJsonCloudEventSerializer"/>.</param>
 public ServiceBusReceiverHost(EventSubscriberHostArgs args, IEventDataConverter <MicrosoftServiceBus.Message>?eventDataConverter = null)
     : base(args, eventDataConverter ?? new MicrosoftServiceBusMessageConverter(new NewtonsoftJsonCloudEventSerializer()))
 {
 }