示例#1
0
 public AuthenticatedHttpClientHandler(RefitServiceAttribute refitServiceAttribute)
 {
     _refitConfig           = EngineContext.Current.GetAppModuleConfig <RefitConfig>();
     _refitServiceAttribute =
         refitServiceAttribute ?? throw new ArgumentNullException(nameof(refitServiceAttribute));
     _logger = EngineContext.Current.Resolve <ILogger <AuthenticatedHttpClientHandler> >();
 }
示例#2
0
        public async Task <IActionResult> Get(int id)
        {
            var quoteClient = RefitExtensions.InstanciateClient <IQuoteClient>(RefitConfig.GetHttpClient());

            var result = (await quoteClient.GetQuote(id)).Content;

            //var result = (await this.QuoteClient.GetQuote(id)).Content;
            return(this.Ok(result));
        }
示例#3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        /// <summary>
        /// Configures the services.
        /// </summary>
        /// <param name="services">The services.</param>
        /// <returns></returns>
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            //var logger = Framework.Logging.Log4Net.LoggerFactory.Create(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            Logger.Info("Application startup - Initializing the Infra Services Configuration");
            try
            {
                //services.Configure<CookiePolicyOptions>(options =>
                //{
                //    // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                //    options.CheckConsentNeeded = context => true;
                //    options.MinimumSameSitePolicy = SameSiteMode.None;
                //});

                var customSettings = this.Configuration.GetSection("CustomSettings").Get <CustomSettings>();
                Logger.Info($"Application startup - Allowed origins: {string.Join(",", customSettings.AllowedOrigins)}");

                services.AddCors();

                services.AddAutofac();

                //services.AddCors(options => {
                //    options.AddPolicy("Development", builder => builder
                //    .WithOrigins(customSettings.AllowedOrigins)
                //    .AllowAnyHeader()
                //    .AllowAnyMethod()
                //    .AllowCredentials());
                //});

                this.ConfigureAuthenticationServices(services);


                //services.AddElmah(options =>
                //{
                //    //services.AddElmah(options => option.Path = "you_path_here")
                //    //options.CheckPermissionAction = context => context.User.Identity.IsAuthenticated;
                //});

                services.AddSignalR(config =>
                {
                    config.EnableDetailedErrors = true;
                });

                services.AddDbContext <IdentityDBContext>(options => options.UseSqlServer(this.ConnectionString));
                services.AddMvc()
                //.AddControllersAsServices()
                .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
                .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver());

                services.AddApiVersioning(o =>
                {
                    o.AssumeDefaultVersionWhenUnspecified = true;
                    o.DefaultApiVersion = new ApiVersion(new DateTime(2016, 7, 1));
                });

                SwaggerConfig.EnableServiceSwaggerMiddleware(services);

                services.AddSingleton <IAuthorizationHandler, PolicyPermissionRequiredHandler>();

                RefitConfig.Configure(this.Configuration, services);

                var autofacServiceProvider = IoCConfig.Init(Configuration, services);

                return(autofacServiceProvider);
            }
            catch (Exception ex)
            {
                Logger.Fatal("Application startup - Execption on Infra Services Configuration", ex);
                throw;
            }
            finally
            {
                Logger.Info("Application startup - Ending the Infra Services Configuration");
                Logger.FlushBuffers();
            }
        }