public static IServiceCollection AddRemotingService(this IServiceCollection services) { services.AddSingleton <IRemotingClient, RemotingClient>(); services.AddSingleton <IUserAppServiceClient, UserAppServiceClient>(); services.AddSingleton(_ => RemotingProxyFactory.CreateSimpleKeyValueService()); return(services); }
public static IServiceCollection AddCommonServices(this IServiceCollection services, IBusControl bus, string busHost) { services.AddSingleton <IMobileCodeSender>(_ => new MobileCodeSender( bus, RemotingProxyFactory.CreateSimpleKeyValueService())); EndpointConvention.Map <SendMobileCodeCommand>( new Uri(busHost + RabbitMqReceiveEndpointNames_SmsService)); return(services); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { 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; }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddScoped(_ => RemotingProxyFactory.CreateOrderService()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddHealthChecks(); services.AddSingleton(o => RemotingProxyFactory.CreateSimpleKeyValueService()); services.AddDataProtection() .SetApplicationName("ServiceFabric-DataProtection-CommonTestWeb") .PersistKeysToServiceFabric(); services.AddMvc(); }
public async Task <bool> CreateOrderAsync(OrderDto dto) { var items = await StateManager.GetOrAddAsync <IReliableDictionary2 <Guid, OrderItem> >("Orders"); ServiceEventSource.Current.ServiceMessage(Context, "Received create order request. OrderId: {0}. ProductId: {1}. Quantity: {2}.", dto.Id, dto.ProductId, dto.Quantity); using (ITransaction tx = StateManager.CreateTransaction()) { var order = new OrderItem(dto); var item = await items.AddOrUpdateAsync(tx, order.Id, order, (k, v) => order); //remove stock var inventoryService = RemotingProxyFactory.CreateInventoryService(); var resultRemovingStock = false; try { resultRemovingStock = await inventoryService.RemoveStockAsync(dto); } catch (Exception ex) { ServiceEventSource.Current.ServiceMessage(Context, "Removing stock is error. OrderId: {0}. ProductId: {1}. Quantity: {2}. ErrorMessage: {3}.", dto.Id, dto.ProductId, dto.Quantity, ex.Message); return(false); } if (resultRemovingStock) { ServiceEventSource.Current.ServiceMessage(Context, "Stock removed. OrderId: {0}. ProductId: {1}. Quantity: {2}.", dto.Id, dto.ProductId, dto.Quantity); try { //NOTE Local transaction is failed, will to compensate //throw new Exception("Local transaction is failed"); await tx.CommitAsync(); ServiceEventSource.Current.ServiceMessage(Context, "Order submitted. OrderId: {0}. ProductId: {1}. Quantity: {2}.", dto.Id, dto.ProductId, dto.Quantity); return(true); } catch (Exception ex) { ServiceEventSource.Current.ServiceMessage(Context, "Submitting order is error. OrderId: {0}. ProductId: {1}. Quantity: {2}. ErrorMessage: {3}.", dto.Id, dto.ProductId, dto.Quantity, ex.Message); //compensation, add stock, maybe with retry try { await inventoryService.CompensateStockAsync(dto); } catch (Exception ex1) { //if compensating stock raise ex, just write log, then person deal with this error ServiceEventSource.Current.ServiceMessage(Context, "Compensating stock is error. OrderId: {0}. ProductId: {1}. Quantity: {2}. ErrorMessage: {3}.", dto.Id, dto.ProductId, dto.Quantity, ex1.Message); } return(false); } } else { ServiceEventSource.Current.ServiceMessage(Context, "Removing stock is failed. OrderId: {0}. ProductId: {1}. Quantity: {2}.", dto.Id, dto.ProductId, dto.Quantity); return(false); } } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddHealthChecks(); //基础服务 #if !DEBUG services.AddDataProtection() .SetApplicationName("EAP-ApiGateway") .PersistKeysToServiceFabric(); #endif services.AddMemoryCache(); services.AddHttpContextAccessor(); services.Configure <FormOptions>(opt => { opt.MultipartBodyLengthLimit = int.MaxValue; }); services.AddHttpClient <IIdentityService, IdentityService>(); // Register the Swagger services services.AddSwaggerDocument(config => { config.PostProcess = document => { document.Info.Version = "v1"; document.Info.Title = "EAP API"; document.Info.Description = "Enterprise Apps Platform API"; document.Info.TermsOfService = "None"; document.SecurityDefinitions.Add("Bearer", new NSwag.SwaggerSecurityScheme { Description = "JWT Authorization header using the Bearer scheme. Example: \"Bearer {token}\"", Name = "Authorization", Type = NSwag.SwaggerSecuritySchemeType.ApiKey, In = NSwag.SwaggerSecurityApiKeyLocation.Header }); document.Security.Add(new NSwag.SwaggerSecurityRequirement { { "Bearer", new string[] { } }, }); }; }); //公共依赖 services.AddSingleton(CreateMapper()); services.AddSingleton(RemotingProxyFactory.CreateSimpleKeyValueService()); var(bus, bus_option) = this.CreateBus("RabbitMQ"); services.AddCommonServices(bus, bus_option.HostAddress); //业务依赖 AppComponent.TheStartup.ConfigureServices(services); Attachment.TheStartup.ConfigureServices(services); ConfigMgmt.TheStartup.ConfigureServices(services); EnterpriseContact.TheStartup.ConfigureServices(services); GroupFile.TheStartup.ConfigureServices(services); InstantMessage.TheStartup.ConfigureServices(services); NotifyStartup.ConfigureServices(services); //Application Parts var assemblyEC = typeof(EnterpriseContact.TheStartup).GetTypeInfo().Assembly; var partEC = new AssemblyPart(assemblyEC); //TODO 没有加ConfigMgmtApi,也能用? //var assemblyCM=typeof() services.AddMvc() .ConfigureApplicationPartManager(apm => apm.ApplicationParts.Add(partEC)) .SetCompatibilityVersion(CompatibilityVersion.Version_2_2); //Authentication var idSvrOption = Configuration.GetSection("IdSvr").Get <IdSvrOption>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.Authority = idSvrOption.IssuerUri; options.RequireHttpsMetadata = idSvrOption.RequireHttps; options.Audience = "eap.api"; options.TokenValidationParameters = new TokenValidationParameters { NameClaimType = "preferred_username", ValidateAudience = false, ValidateIssuer = false, ValidateActor = false, ValidateLifetime = true, LifetimeValidator = (before, expires, token, param) => { return(expires > DateTime.UtcNow); }, }; }); //相关配置 services.Configure <IdSvrOption>(Configuration.GetSection("IdSvr")); services.Configure <MinioOption>(Configuration.GetSection("Minio")); }