Exemple #1
0
        /// <summary>
        /// Register holiday
        /// </summary>
        /// <param name="services"></param>
        /// <param name="optionsAction"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static IServiceCollection AddHoliday(this IServiceCollection services, Action <MSDIHolidayOptions> optionsAction = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var holidayManager         = HolidayManagerFactory.Create();
            var holidayProviderManager = new HolidayProviderManager();

            InternalSingleInstanceServiceLocator.SetHolidayManager(holidayManager);
            InternalSingleInstanceServiceLocator.SetHolidayProviderManager(holidayProviderManager);

            var options = new MSDIHolidayOptions(holidayProviderManager);

            //todo 读取配置,获取 Holiday 配置信息

            //todo 读取配置,获得运行时节日配置信息
            //扫描并生成到 options.RuntimeFixedHolidayFunc
            //读取并激活

            //To Activate Holiday options
            optionsAction?.Invoke(options);

            //To Activate Weekend options.
            services.RegisterWeekendDefinitions(options);

            services.RegisterManagers(holidayManager, holidayProviderManager);
            services.RegisterGetters();

            return(services);
        }
Exemple #2
0
        /// <summary>
        /// Register holiday
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="optionsAction"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static ContainerBuilder RegisterHoliday(this ContainerBuilder builder, Action <AutofacHolidayOptions> optionsAction = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var holidayManager         = HolidayManagerFactory.Create();
            var holidayProviderManager = new HolidayProviderManager();

            InternalSingleInstanceServiceLocator.SetHolidayManager(holidayManager);
            InternalSingleInstanceServiceLocator.SetHolidayProviderManager(holidayProviderManager);

            var options = new AutofacHolidayOptions(holidayProviderManager);

            //todo 读取配置,获取 Holiday 配置信息

            //todo 读取配置,获得运行时节日配置信息
            //扫描并生成到 options.RuntimeFixedHolidayFunc
            //读取并激活

            //To Activate Holiday options
            optionsAction?.Invoke(options);

            //To Activate Weekend options.
            builder.RegisterWeekendDefinitions(options);

            builder.RegisterManagers(holidayManager, holidayProviderManager);
            builder.RegisterGetters();

            return(builder);
        }