public CustomersController(IRepository <Customer> repo, IMapper mapper, IOptions <MyOptions> optionsAccesor,
                            IRepository <User> userRepo, IHostingEnvironment hostingEnvironment) : base(mapper, userRepo)
 {
     _repo               = repo;
     _options            = optionsAccesor.Value;
     _hostingEnvironment = hostingEnvironment;
 }
Example #2
0
 public ConfigController(IConfiguration config, IOptions <MyOptions> myOption, IOptions <MySubOptions> mySubOption, DBHelper dbHelper)
 {
     this._config       = config;
     this._myOptions    = myOption.Value;
     this._mySubOptions = mySubOption.Value;
     this._dbHelper     = dbHelper;
 }
 public WeightService(WeightRepository repository, PatientRepository patientRepository, IUnitWork unitWork, IOptions <MyOptions> optionsAccessor)
 {
     _repository        = repository;
     _patientRepository = patientRepository;
     _unitWork          = unitWork;
     _optionsAccessor   = optionsAccessor.Value;
 }
Example #4
0
    public void BindingDoesNotThrowIfReloadedDuringBinding()
    {
        var testFileProvider = new TestFileProvider(
            new TestFile("Number", "-2"),
            new TestFile("Text", "Foo"));

        var config = new ConfigurationBuilder()
                     .AddKeyPerFile(o => o.FileProvider = testFileProvider)
                     .Build();

        MyOptions options = null;

        using (var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(250)))
        {
            void ReloadLoop()
            {
                while (!cts.IsCancellationRequested)
                {
                    config.Reload();
                }
            }

            _ = Task.Run(ReloadLoop);

            while (!cts.IsCancellationRequested)
            {
                options = config.Get <MyOptions>();
            }
        }

        Assert.Equal(-2, options.Number);
        Assert.Equal("Foo", options.Text);
    }
        public HomeController(
            ILogger <HomeController> logger,
            IConfiguration config,
            IOptionsMonitor <MyOptions> optionAccessor,
            IOptionsMonitor <MyOptionsWithDelegateConfig> optionsAccessorWithDelegateConfig,
            IOptionsMonitor <MySubOptions> subOptionsAccessor,
            IOptionsSnapshot <MyOptions> snapshotOptionsAccessor,
            IOptionsSnapshot <MyOptions> namedOptionsAccessor,
            IMyDependency myDependency,
            OperationService operationService,
            IOperationTransient transientOperation,
            IOperationScoped scopedOperation,
            IOperationSingleton singletonOperation,
            IOperationSingletonInstance instanceOperation)
        {
            _logger = logger;
            _config = config;

            _options = optionAccessor.CurrentValue;
            _optionsWithDelegateConfig = optionsAccessorWithDelegateConfig.CurrentValue;
            _subOptions      = subOptionsAccessor.CurrentValue;
            _snapshotOptions = snapshotOptionsAccessor.Value;
            _named_options_1 = namedOptionsAccessor.Get("named_options_1");
            _named_options_2 = namedOptionsAccessor.Get("named_options_2");

            _myDependency      = myDependency;
            OperationService   = operationService;
            TransientOperation = transientOperation;
            ScopedOperation    = scopedOperation;
            SingletonOperation = singletonOperation;
            InstanceOperation  = instanceOperation;
        }
Example #6
0
        public static void UseHost_binds_parsed_arguments_to_options()
        {
            const int myValue     = 4224;
            string    commandLine = $"-{nameof(MyOptions.MyArgument)} {myValue}";
            MyOptions options     = null;

            var rootCmd = new RootCommand();

            rootCmd.AddOption(new Option <int>($"-{nameof(MyOptions.MyArgument)}"));
            rootCmd.Handler = CommandHandler.Create((IHost host) =>
            {
                options = host.Services
                          .GetRequiredService <IOptions <MyOptions> >()
                          .Value;
            });

            int result = new CommandLineBuilder(rootCmd)
                         .UseHost(host =>
            {
                host.ConfigureServices(services =>
                {
                    services.AddOptions <MyOptions>().BindCommandLine();
                });
            })
                         .Build()
                         .Invoke(commandLine);

            Assert.Equal(0, result);
            Assert.NotNull(options);
            Assert.Equal(myValue, options.MyArgument);
        }
Example #7
0
 public HomeController(
     IOptionsMonitor <MyOptions> optionsAccessor,
     ILogger <HomeController> logger)
 {
     _options = optionsAccessor.CurrentValue;
     _logger  = logger;
 }
Example #8
0
 public HomeController(IOptions <MyOptions> optionAccessor, IOptions <SubOptions> subOptionAccessor, IOptionsSnapshot <SubOptions> optionsSnapshot)
 {
     options    = optionAccessor.Value;
     subOptions = subOptionAccessor.Value;
     //通过name读取对应的选项
     subOptions1 = optionsSnapshot.Get("sub1");
     subOptions2 = optionsSnapshot.Get("sub2");
 }
Example #9
0
 public AccountController(mJsonResult jsonResult, ILogger <AccountController> logger,
                          IOptions <MyOptions> configOptions, IOptionsSnapshot <MyOptions> snapshot)
 {
     this.json     = jsonResult;
     this._logger  = logger;
     this.options  = configOptions == null ? null : configOptions.Value;
     this.options2 = configOptions == null ? null : snapshot.Value;
 }
Example #10
0
 public MessageCenterController(
     IOptions <MyOptions> options,
     IMyHelper myHelper
     )
 {
     _options  = options.value;
     _myHelper = myHelper;
 }
 public OptionController(IOptions <MyOptions> optionAccessor,
                         IOptions <MyOptionsWithDelegateConfig> myOptionsWithDelegateConfig,
                         IOptionsSnapshot <MySnapshotOptions> snapshotOptionsAccessor)
 {
     _myOptions = optionAccessor.Value;
     _myOptionsWithDelegateConfig = myOptionsWithDelegateConfig.Value;
     _snapshotOptions             = snapshotOptionsAccessor.Value;
 }
 public BloodPressureService(IUnitWork unitWork, BloodPressureRepository bloodPressureRepository,
                             PatientRepository patientRepository, IOptions <MyOptions> optionsAccessor)
 {
     _unitWork                = unitWork;
     _patientRepository       = patientRepository;
     _bloodPressureRepository = bloodPressureRepository;
     _optionsAccessor         = optionsAccessor.Value;
 }
 public AlarmService(AlarmRepository repository, DoctorRepository doctorRepository, MessageRepository messageRepository, IUnitWork unitWork, IOptions <MyOptions> optionsAccessor)
 {
     _repository        = repository;
     _unitWork          = unitWork;
     _doctorRepository  = doctorRepository;
     _messageRepository = messageRepository;
     _optionsAccessor   = optionsAccessor.Value;
 }
Example #14
0
 public OptionsController(
     IOptionsMonitor <MyOptions> optionsMonitor,
     IOptionsMonitor <MySubOptions> subOptionsMonitor
     )
 {
     options    = optionsMonitor.CurrentValue;
     subOptions = subOptionsMonitor.CurrentValue;
 }
Example #15
0
 public AlertOwnerService(IGoogleSpreadSheetClient googleSpreadSheetClient,
                          ITypeConverter <LocalDate> converter, ITimeService timeService, IOptions <MyOptions> options)
 {
     _googleSpreadSheetClient = googleSpreadSheetClient;
     _converter   = converter;
     _timeService = timeService;
     _options     = options.Value;
 }
 public static void ProcessQueueMessage(
     [QueueTrigger("myqueue")] string message,
     ILogger logger,
     MyOptions options)
 {
     logger.LogInformation(message);
     logger.LogInformation(options.MyDatabase);
 }
Example #17
0
        public HomeController(IOptions <MyOptions> optionAccessor, IOptions <SubOptions> subOptionAccessor, IOptionsSnapshot <SubOptions> nameOptionsAccess)
        {
            options    = optionAccessor.Value;
            subOptions = subOptionAccessor.Value;

            subOption1 = nameOptionsAccess.Get("sub1");
            subOption2 = nameOptionsAccess.Get("sub2");
        }
Example #18
0
 private MyOptionsResult GetMyOptionsResult(MyOptions myOptions)
 {
     return(new MyOptionsResult
     {
         OptionString = myOptions.StringOption,
         OptionTime = myOptions.DateTimeOption.ToLongTimeString(),
         OptionNumber = myOptions.NumberOption
     });
 }
        public void MapValueEnqueues()
        {
            var instance = QueueMapper <MyOptions, int> .Create(opt => opt.Queue);

            var options = new MyOptions();

            instance.MapValue(options, 10);
            options.Queue.Single().ShouldBe(10);
        }
        public void MapValueAdds()
        {
            var instance = CollectionMapper <MyOptions, int> .Create(opt => opt.Collection);

            var options = new MyOptions();

            instance.MapValue(options, 10);
            options.Collection.Single().ShouldBe(10);
        }
        public void MapValueAdds()
        {
            var instance = StackMapper <MyOptions, int> .Create(opt => opt.Stack);

            var options = new MyOptions();

            instance.MapValue(options, 10);
            options.Stack.Single().ShouldBe(10);
        }
Example #22
0
        public ContentResult OnGet()
        {
            var myOpts = new MyOptions();

            Configuration.GetSection("MyOptions").Bind(myOpts);

            return(Content($"Option1: {myOpts.Option1} \n" +
                           $"Option2: {myOpts.Option2}"));
        }
 public PollingStatsForOrganizationService(ICalcStatsForOrg calcStatsService,
                                           ISortContributors sortContributorsService, IHandleResults handleResultService,
                                           IOptionsMonitor <MyOptions> optionsMonitor)
 {
     _calcStatsService        = calcStatsService;
     _sortContributorsService = sortContributorsService;
     _handleResultService     = handleResultService;
     _options = optionsMonitor.CurrentValue;
 }
Example #24
0
 public OssRepository(IOptions <MyOptions> optionsAccessor)
 {
     _optionsAccessor = optionsAccessor.Value;
     _client          = new OssClient(new OssCredential
     {
         AccessKeyId     = CommConstant.OssAccessKeyId,
         AccessKeySecret = CommConstant.OssAccessKeySecret
     });
 }
Example #25
0
        public void Configuration(IAppBuilder app)
        {
            var builder = new ContainerBuilder();

            builder.RegisterModule(new DataModule("WebShopConnection", app));

            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            var container = builder.Build();

            // REPLACE THE MVC DEPENDENCY RESOLVER WITH AUTOFAC
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            // REGISTER WITH OWIN
            app.UseAutofacMiddleware(container);
            app.UseAutofacMvc();

            app.UseCookieAuthentication(MyOptions.OptionCookies());
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            //var facebookOptions = new FacebookAuthenticationOptions
            //{
            //    AppId = "350879062040009",
            //    AppSecret = "f1105a9743238e20671f63d37b373298"
            //};

            //facebookOptions.Scope.Add("email");

            //facebookOptions.Fields.Add("name");
            //facebookOptions.Fields.Add("email");

            //app.UseFacebookAuthentication(facebookOptions);

            //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            //{
            //    ClientId = "",
            //    ClientSecret = ""
            //});
        }
 public HomeController(
     IDatetime datetime,
     IOptions <MyOptions> setting,
     ProductContext db
     )
 {
     this._datetime = datetime;
     this._options  = setting.Value;
     this._db       = db;
 }
 public UserController(UserService userService, DiagnoseService diagnoseService,
                       TreatService treatService, TreatImageService treatImageService, IOptions <MyOptions> optionsAccessor)
 {
     _userService       = userService;
     _diagnoseService   = diagnoseService;
     _treatService      = treatService;
     _treatImageService = treatImageService;
     _optionsAccessor   = optionsAccessor.Value;
     _lovePlatformApi   = new LovePlatformAdminApi(_optionsAccessor.WebApiUrl);
 }
 public PatientEduService(PatientEduRepository repository, DoctorRepository doctorRepository, CourseRepository courseRepository, SystemRepository systemRepository, MessageRepository messageRepository, IUnitWork unitWork, IOptions <MyOptions> optionsAccessor)
 {
     _unitWork          = unitWork;
     _optionsAccessor   = optionsAccessor.Value;
     _repository        = repository;
     _doctorRepository  = doctorRepository;
     _courseRepository  = courseRepository;
     _systemRepository  = systemRepository;
     _messageRepository = messageRepository;
 }
        public void MapValueWithNullCollectionThrows()
        {
            var myOptions = new MyOptions
            {
                Collection = null
            };
            var instance = CollectionMapper <MyOptions, int> .Create(opt => opt.Collection);

            Should.Throw <ConfigurationException>(() => instance.MapValue(myOptions, 0));
        }
        public SignController(IOptions <MyOptions> optionsAccessor)
        {
            // 实际场景用
            _optionsAccessor = optionsAccessor.Value;
            _weixinHelper    = new WeixinHelper(_optionsAccessor.WeixinAppId, _optionsAccessor.WeixinAppSecret);
            _lovePlatformApi = new LovePlatformApi(_optionsAccessor.WebApiUrl);

            // 开发环境用
            //_lovePlatformApi = new LovePlatformApi("http://106.14.14.219:8081/");
        }
        public void ParseSuccess()
        {
            var opts = new MyOptions();

            var argSet = new ArgumentSet()
                .Required(opts.RunMe)
                .Required(opts.File)
                .Optional(opts.Flag)
                .Optional(opts.Names)
                .Optional(opts.Sport)
                .OnMatch(() =>
                {
                    opts.RunMe.IsPresent.ShouldBeTrue();

                    opts.File.Value.ShouldBe(@"C:\some\path\file.txt");
                    // value is convenience to calling Values.Single()
                    opts.File.Value.ShouldBe(@"C:\some\path\file.txt");
                    opts.File.Values.Single().ShouldBe(@"C:\some\path\file.txt");
                    
                    // optionl flag, must test if present
                    if (!opts.Sport.IsPresent)
                    {
                        // default value has been assigned
                        opts.Sport.Value.ShouldBe(MyOptions.SportDefault);
                    }

                    // safe to enumerate an optional list
                    opts.Names.Values.Any("Jill").ShouldBeTrue();
                    opts.Names.Values.Any("Bob").ShouldBeTrue();
                }),

            var args = new string[] {"RunMe", "--Names", "Bob", "Jill", "--file", @"C:\some\path\file.txt"};
            LineCommander.Parse(args, argSet)
                .OnError(bestMatch =>
                {
                    Log.Error($"No matching argument set: did you mean '{bestMatch}'");
                });
    }