예제 #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            this.RegisterButton.TouchUpInside += (sender, e) => {
                RegistrationViewController vc = new RegistrationViewController();
                this.PresentViewController(vc, true, null);
            };

            this.LoginButton.TouchUpInside += (sender, e) => {
                LoginViewController vc = new LoginViewController();
                this.PresentViewController(vc, true, null);
            };

            this.GetDataButton.TouchUpInside += async(sender, e) => {
                TestDataService service = new TestDataService();
                await service.AddTestData();

                try
                {
                    TestData data = await service.GetMostRecentItem();

                    this.BeginInvokeOnMainThread(() => {
                        this.StatusLabel.Text = "Data retrieved! Date created was";
                        this.DataLabel.Text   = data.DateCreated.ToString("G");
                    });
                }
                catch (Exception ex)
                {
                    this.BeginInvokeOnMainThread(() => {
                        this.StatusLabel.TextColor = UIColor.Red;
                        this.StatusLabel.Text      = ex.Message;
                    });
                }
            };
        }
예제 #2
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            IServiceProvider serviceProvider;

            try
            {
                services.AddAuthentication(o =>
                {
                    o.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
                })
                .AddJwtBearer(o =>
                {
                    o.Authority = $"https://login.microsoftonline.com/{Configuration.ApiAuthentication.TenantId}";
                    o.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
                    {
                        RoleClaimType  = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role",
                        ValidAudiences = new List <string>
                        {
                            UseSandbox?Configuration.SandboxApiAuthentication.Audience: Configuration.ApiAuthentication.Audience,
                            UseSandbox ? Configuration.SandboxApiAuthentication.ClientId : Configuration.ApiAuthentication.ClientId
                        }
                    };
                    o.Events = new JwtBearerEvents()
                    {
                        OnTokenValidated = context => { return(Task.FromResult(0)); }
                    };
                });

                services.AddLocalization(opts => { opts.ResourcesPath = "Resources"; });

                services.Configure <RequestLocalizationOptions>(options =>
                {
                    options.DefaultRequestCulture = new RequestCulture("en-GB");
                    options.SupportedCultures     = new List <CultureInfo> {
                        new CultureInfo("en-GB")
                    };
                    options.SupportedUICultures = new List <CultureInfo> {
                        new CultureInfo("en-GB")
                    };
                    options.RequestCultureProviders.Clear();
                });

                IMvcBuilder mvcBuilder;
                if (_env.IsDevelopment())
                {
                    mvcBuilder = services.AddMvc(opt => { opt.Filters.Add(new AllowAnonymousFilter()); });
                }
                else
                {
                    mvcBuilder = services.AddMvc();
                }

                mvcBuilder
                .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix,
                                     opts => { opts.ResourcesPath = "Resources"; })
                .AddDataAnnotationsLocalization()
                .AddControllersAsServices()
                .AddFluentValidation(fvc => fvc.RegisterValidatorsFromAssemblyContaining <Startup>());

                services.AddSwaggerGen(c =>
                {
                    c.SwaggerDoc("v1", new Info {
                        Title = "SFA.DAS.AssessorService.Application.Api", Version = "v1"
                    });
                    c.CustomSchemaIds(i => i.FullName);
                    if (_env.IsDevelopment())
                    {
                        var basePath = AppContext.BaseDirectory;
                        var xmlPath  = Path.Combine(basePath, "SFA.DAS.AssessorService.Application.Api.xml");
                        c.IncludeXmlComments(xmlPath);
                    }
                });

                services.AddHttpClient <ProviderRegisterApiClient>("ProviderRegisterApiClient", config =>
                {
                    config.BaseAddress = new Uri(Configuration.ProviderRegisterApiAuthentication.ApiBaseAddress);     //  "https://findapprenticeshiptraining-api.sfa.bis.gov.uk"
                    config.DefaultRequestHeaders.Add("Accept", "Application/json");
                })
                .SetHandlerLifetime(TimeSpan.FromMinutes(5));

                services.AddHttpClient <ReferenceDataApiClient>("ReferenceDataApiClient", config =>
                {
                    config.BaseAddress = new Uri(Configuration.ReferenceDataApiAuthentication.ApiBaseAddress);     //  "https://at-refdata.apprenticeships.sfa.bis.gov.uk/api"
                    config.DefaultRequestHeaders.Add("Accept", "Application/json");
                })
                .SetHandlerLifetime(TimeSpan.FromMinutes(5));

                services.AddHttpClient <CompaniesHouseApiClient>("CompaniesHouseApiClient", config =>
                {
                    config.BaseAddress = new Uri(Configuration.CompaniesHouseApiAuthentication.ApiBaseAddress);     //  "https://api.companieshouse.gov.uk"
                    config.DefaultRequestHeaders.Add("Accept", "Application/json");
                })
                .SetHandlerLifetime(TimeSpan.FromMinutes(5));

                services.AddHttpClient <RoatpApiClient>("RoatpApiClient", config =>
                {
                    config.BaseAddress = new Uri(Configuration.RoatpApiAuthentication.ApiBaseAddress);     //  "https://at-providers-api.apprenticeships.education.gov.uk"
                    config.DefaultRequestHeaders.Add("Accept", "Application/json");
                })
                .SetHandlerLifetime(TimeSpan.FromMinutes(5));

                services.AddHealthChecks();

                serviceProvider = ConfigureIOC(services);

                if (_env.IsDevelopment())
                {
                    TestDataService.AddTestData(serviceProvider.GetService <AssessorDbContext>());
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error during Startup Configure Services");
                throw;
            }

            return(serviceProvider);
        }