Пример #1
0
        public static IServiceCollection AddEventHandler(this IServiceCollection services, Action <EventhandlerOptions> setupAction)
        {
            if (setupAction == null)
            {
                throw new ArgumentNullException(nameof(setupAction), $"{nameof(setupAction)} cannot be null.");
            }

            var options = new EventhandlerOptions();

            setupAction.Invoke(options);

            ConfigureEventhandlerOptions(services, options);

            RegisterServices(services);

            return(services);
        }
Пример #2
0
        private static void ConfigureEventhandlerOptions(IServiceCollection services, EventhandlerOptions options)
        {
            ValidateMandatoryField(options.AppId, nameof(options.AppId));
            ValidateMandatoryField(options.AppName, nameof(options.AppName));
            ValidateMandatoryField(options.EventEndpointUrl, nameof(options.EventEndpointUrl));
            ValidateMandatoryField(options.EventEndpointNamespace, nameof(options.EventEndpointNamespace));
            ValidateMandatoryField(options.EventEndpointApikey, nameof(options.EventEndpointApikey));
            ValidateMandatoryField(options.EventEndpointOwnerkey, nameof(options.EventEndpointOwnerkey));
            ValidateMandatoryField(options.MessageVersion, nameof(options.MessageVersion));
            ValidateMandatoryField(options.Version, nameof(options.Version));

            services.Configure <EventhandlerOptions>(opt =>
            {
                opt.AppId                  = options.AppId;
                opt.AppName                = options.AppName;
                opt.EventEndpointUrl       = options.EventEndpointUrl;
                opt.EventEndpointNamespace = options.EventEndpointNamespace;
                opt.EventEndpointApikey    = options.EventEndpointApikey;
                opt.EventEndpointOwnerkey  = options.EventEndpointOwnerkey;
                opt.MessageVersion         = options.MessageVersion;
                opt.Version                = options.Version;
            });
        }