├── .dockerignore ├── .gitattributes ├── .gitignore ├── .vs ├── ProjectEvaluation │ ├── chatgptwriteproject.metadata.v5.2 │ ├── chatgptwriteproject.projects.v5.2 │ ├── efcore开发模板.metadata.v5.2 │ ├── efcore开发模板.metadata.v6.1 │ ├── efcore开发模板.projects.v5.2 │ └── efcore开发模板.projects.v6.1 ├── chatgptwriteproject │ └── FileContentIndex │ │ ├── 4bf11d2b-44ab-4b75-aea4-ffcd695276db.vsidx │ │ ├── 79b9260d-e5f6-40d1-8fa9-0a240061f98c.vsidx │ │ ├── b6c1578a-dbbe-4dfa-85a3-df3fbf570913.vsidx │ │ ├── c4ab6445-363d-44b8-89ae-3e5bbbdee3d6.vsidx │ │ └── read.lock ├── efcore-template │ ├── DesignTimeBuild │ │ └── .dtbcache.v2 │ ├── config │ │ └── applicationhost.config │ └── v17 │ │ ├── .futdcache.v2 │ │ └── .suo └── efcore开发模板 │ ├── DesignTimeBuild │ └── .dtbcache.v2 │ ├── FileContentIndex │ ├── 4c1d815d-a3c4-4549-8ac6-ee9f6fd19fd0.vsidx │ ├── 5e881f66-3f98-4c71-827d-8cac41b858be.vsidx │ ├── 62cf10e2-c775-4d9c-8a60-b0e7a50ede24.vsidx │ └── read.lock │ └── v17 │ ├── .futdcache.v2 │ └── .suo ├── Common.Cache ├── CacheExtentions.cs ├── Common.Cache.csproj └── Options │ ├── CacheOptions.cs │ └── CacheType.cs ├── Common.DapperDal ├── Common.DapperDal.csproj ├── DalBaseOfTEntity.Count.cs ├── DalBaseOfTEntity.Delete.cs ├── DalBaseOfTEntity.Execute.OtherConn.cs ├── DalBaseOfTEntity.Execute.cs ├── DalBaseOfTEntity.ExecuteScalar.OtherConn.cs ├── DalBaseOfTEntity.ExecuteScalar.cs ├── DalBaseOfTEntity.Exsit.cs ├── DalBaseOfTEntity.Get.cs ├── DalBaseOfTEntity.GetFirst.cs ├── DalBaseOfTEntity.GetList.cs ├── DalBaseOfTEntity.GetListPaged.cs ├── DalBaseOfTEntity.GetSet.cs ├── DalBaseOfTEntity.GetTop.cs ├── DalBaseOfTEntity.Insert.cs ├── DalBaseOfTEntity.Query.OtherConn.cs ├── DalBaseOfTEntity.Query.cs ├── DalBaseOfTEntity.QueryDataSet.OtherConn.cs ├── DalBaseOfTEntity.QueryDataSet.cs ├── DalBaseOfTEntity.QueryFirst.OtherConn.cs ├── DalBaseOfTEntity.QueryFirst.cs ├── DalBaseOfTEntity.QueryMultiple.OtherConn.cs ├── DalBaseOfTEntity.QueryMultiple.cs ├── DalBaseOfTEntity.SoftDelete.cs ├── DalBaseOfTEntity.SwitchActive.cs ├── DalBaseOfTEntity.Update.cs ├── DalBaseOfTEntity.cs ├── DalConfiguration.cs ├── DalOptions.cs ├── Expressions │ ├── ExpressionUtility.cs │ ├── PredicateBuilder.cs │ ├── PredicateExtensions.cs │ ├── QueryBuilder.cs │ ├── QueryFunctions.cs │ ├── SortDirection.cs │ └── SortingExtensions.cs ├── Implementor │ └── DalImplementor.cs ├── Mapper │ ├── AutoClassMapper.cs │ ├── AutoEntityMapper.cs │ ├── ClassMapper.cs │ ├── PluralizedAutoClassMapper.cs │ └── PropertyMap.cs ├── Predicate │ ├── GetMultiplePredicate.cs │ ├── GetMultipleResult.cs │ └── Predicates.cs ├── Sql │ ├── SqlDialectBase.cs │ ├── SqlGenerator.cs │ └── SqlServerDialect.cs └── Utils │ ├── ExpressionExtensions.cs │ └── ReflectionHelper.cs ├── Common.DistributedId ├── AsyncHelper.cs ├── Common.DistributedId.csproj ├── DistributedId.cs ├── DistributedIdExtentions.cs ├── DistributedIdOptions.cs ├── Guid │ └── GuidHelper.cs ├── IDistributedId.cs └── Snowflake │ ├── DisposableAction.cs │ ├── IdWorker.cs │ ├── InvalidSystemClock.cs │ └── TImeExtensions.cs ├── Common.DistributedLock.Abstractions ├── Common.DistributedLock.Abstractions.csproj ├── DistributedLockOptions.cs ├── IDistributedLock.cs └── LockType.cs ├── Common.DistributedLock.InMemory ├── Common.DistributedLock.InMemory.csproj └── InMemoryDistributedLock.cs ├── Common.DistributedLock.Redis ├── Common.DistributedLock.Redis.csproj └── RedisDistributedLock.cs ├── Common.Es ├── Common.Es.csproj └── Elasticsearchs │ ├── Es.Context │ ├── ArticleEsContext.cs │ └── EsContext.cs │ ├── Es.Foundation │ ├── EsBase.cs │ ├── EsClientExtension.cs │ ├── EsConfig.cs │ ├── EsOption.cs │ └── IEsBase.cs │ ├── Es.Parameters │ └── EsParameter.cs │ └── Es.Response │ ├── EsData.cs │ └── EsResult.cs ├── Common.Grpc ├── Common.Grpc.csproj └── GrpcPool │ ├── GrpcClientPool.cs │ └── IGrpcClientFactory.cs ├── Common.MessageMiddleware ├── Common.MessageMiddleware.csproj ├── Extensions │ └── ProgramExtensions.cs ├── Factory │ ├── IMQFactory.cs │ ├── MQConfig.cs │ ├── MQFactory.cs │ ├── MQFactoryBuilder.cs │ └── MQType.cs ├── IMQPublisher.cs ├── Kafka │ ├── BaseOptions.cs │ ├── Consumer │ │ ├── ConsumerOptions.cs │ │ └── KafkaListenerHostService.cs │ ├── KafkaExtensions.cs │ └── Producers │ │ ├── IKafkaProduce.cs │ │ ├── KafkaProduce.cs │ │ ├── KafkaPublisher.cs │ │ └── ProducerOptions.cs ├── ListenerConfig.cs ├── MQListener.cs ├── Properties │ └── launchSettings.json ├── RabbitMQ │ ├── IRabbitMQConnection.cs │ ├── MQListenerHostService.cs │ ├── MQPublisher.cs │ ├── RabbitMQChannelPooledObjectPolicy.cs │ ├── RabbitMQConnection.cs │ └── RabbitMQSetting.cs ├── ServiceCollectionExtensions.cs └── configs │ ├── mqsettings.json │ └── rabbitmq.json ├── Common.MongoDb ├── Common.MongoDb.csproj ├── MongoDbOptions.cs ├── MongoDbService.cs └── MongoDbServiceCoolectionExtensions.cs ├── Common.Redis ├── Common.Redis.csproj ├── Configuration │ ├── RedisConfiguration.cs │ ├── RedisHost.cs │ └── ServerEnumerationStrategy.cs ├── CsRedisCache.cs ├── Extensions │ ├── DependencyInjectionExtensions.cs │ └── LinqExtensions.cs ├── GeneratorID.cs ├── IRedisCache.cs ├── ISerializer.cs ├── PooledConnectionMultiplexer.cs ├── RedisCache.cs ├── Serializer │ ├── BsonSerializer.cs │ ├── JsonSerializer.cs │ ├── MsgPackSerializer.cs │ ├── ProtobufSerializer.cs │ ├── SerializerEnum.cs │ └── SerializerHelper.cs └── ServerIteration │ ├── ServerEnumerable.cs │ └── ServerIteratorFactory.cs ├── Common.RepositoryComponent ├── BaseRepo │ ├── IReadRepository.cs │ ├── IWriteRepository.cs │ ├── ReadRepository.cs │ ├── ReadRepositoryBase.cs │ ├── WriteRepository.cs │ └── WriteRepositoryBase.cs ├── Common.RepositoryComponent.csproj ├── DbFactories │ └── DbFactory.cs ├── Extensions │ └── LinqExtensions.cs └── Page │ ├── PaginatedList.cs │ ├── PaginatedListBase.cs │ ├── PaginatedOptions.cs │ └── RequestPageBase.cs ├── Common.RestSharpClient ├── ApiClient.cs ├── ApiException.cs ├── ClientUtils.cs ├── Common.RestSharpClient.csproj ├── Configuration.cs ├── ExceptionFactory.cs ├── GateApiException.cs ├── GlobalConfiguration.cs ├── HttpMethod.cs ├── IApiAccessor.cs ├── IApiResponse.cs ├── IAsynchronousClient.cs ├── IReadableConfiguration.cs ├── ISynchronousClient.cs ├── Multimap.cs ├── OpenAPIDateConverter.cs └── RequestOptions.cs ├── Common.SqlSugar ├── Common.SqlSugar.csproj ├── Extensions │ ├── PagedQueryableExtensions.cs │ └── SqlSugarServiceCollectionExtensions.cs ├── Internal │ ├── SqlProfiler.cs │ └── SqlSugarPagedList.cs └── Repositories │ ├── ISqlSugarRepository.cs │ └── SqlSugarRepository.cs ├── Common.Util ├── Common.Util.csproj ├── CryptionHelper.cs ├── Elasticsearchs │ └── Es.Foundation │ │ ├── EsBase.cs │ │ ├── EsClientExtension.cs │ │ ├── EsConfig.cs │ │ ├── EsOption.cs │ │ └── IEsBase.cs ├── EnumHelper.cs ├── Exceptions │ ├── CommonException.cs │ ├── CommonExceptionFilter.cs │ ├── ParamsErrorException.cs │ └── SystemErrorException.cs ├── Jwt │ ├── JwtExtensions.cs │ └── JwtOptions.cs └── Primitives │ ├── AjaxResult.cs │ ├── ShowException.cs │ └── TypeExtentions.cs ├── ConsumerClient ├── ConsumerClient.csproj ├── OrderConsumer.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── appsettings.Development.json └── appsettings.json ├── MicroService ├── Catalog.Service │ ├── Catalogs.Domain │ │ ├── Catalogs.Domain.csproj │ │ ├── Catalogs │ │ │ └── Catalog.cs │ │ ├── Dtos │ │ │ └── ProductDto.cs │ │ ├── Events │ │ │ ├── CreateOrderEvent.cs │ │ │ ├── IDomainEvent.cs │ │ │ ├── IEntity.cs │ │ │ └── ReceiveCreateOrderEvent.cs │ │ └── OutBoxMessage │ │ │ ├── OutBoxMessage.cs │ │ │ └── OutBoxMessageConsumer.cs │ ├── Catalogs.Infrastructure │ │ ├── ApplicationStartup.cs │ │ ├── Catalogs.Infrastructure.csproj │ │ └── Database │ │ │ ├── CatalogContext.cs │ │ │ └── CatalogContextSeed.cs │ └── Catalogs.WebApi │ │ ├── BackgroudServices │ │ └── InitProductListToRedisService.cs │ │ ├── Catalogs.WebApi.csproj │ │ ├── Controllers │ │ └── CatalogController.cs │ │ ├── Handler │ │ └── CreateOrderHandler.cs │ │ ├── Program.cs │ │ ├── Properties │ │ └── launchSettings.json │ │ ├── ViewModel │ │ └── PaginatedViewModel.cs │ │ ├── appsettings.Development.json │ │ ├── appsettings.json │ │ └── wwwroot │ │ └── Img │ │ ├── R.jpg │ │ ├── dog.png │ │ └── phone.jpg ├── Customer.Service │ ├── Custoemr.domain │ │ ├── Customers.Domain.csproj │ │ ├── Customers │ │ │ ├── Customer.cs │ │ │ ├── ICustomerRepository.cs │ │ │ └── MissingCustomer.cs │ │ └── Seedwork │ │ │ └── IUnitOfWork.cs │ ├── Customer.Infrastructure │ │ ├── ApplicationStartup.cs │ │ ├── Customers.Infrastructure.csproj │ │ ├── Database │ │ │ └── CustomerContext.cs │ │ └── Domain │ │ │ ├── Customers │ │ │ └── CustomerRepository.cs │ │ │ └── UnitOfWork.cs │ └── Customer.WebApi │ │ ├── Controllers │ │ └── TokenController.cs │ │ ├── Customers.Center.csproj │ │ ├── GrpcService │ │ └── GrpcCustomerService.cs │ │ ├── Program.cs │ │ ├── Properties │ │ └── launchSettings.json │ │ ├── Service │ │ ├── CustomerService.cs │ │ ├── Dtos │ │ │ ├── AddCustomerDto.cs │ │ │ ├── LoginDto.cs │ │ │ └── TokenDto.cs │ │ └── ICustomerService.cs │ │ ├── appsettings.Development.json │ │ └── appsettings.json ├── GrpcService │ └── GrpcService │ │ ├── CustomerService │ │ └── IGrpcCustomerService.cs │ │ ├── GrpcService.csproj │ │ └── OrderService │ │ └── IGrpcOrderService.cs ├── Message.Service │ └── Message.WebApi │ │ ├── Controllers │ │ └── WeatherForecastController.cs │ │ ├── Message.WebApi.csproj │ │ ├── Program.cs │ │ ├── Properties │ │ └── launchSettings.json │ │ ├── WeatherForecast.cs │ │ ├── appsettings.Development.json │ │ └── appsettings.json ├── Ordering.Service │ ├── Ordering.Domain │ │ ├── Dtos │ │ │ ├── CatalogCopy.cs │ │ │ ├── CreateOrderDto.cs │ │ │ └── OrderDetailDto.cs │ │ ├── Enums │ │ │ └── OrderStatus.cs │ │ ├── Events │ │ │ ├── CreateOrderEvent.cs │ │ │ ├── IDomainEvent.cs │ │ │ └── IEntity.cs │ │ ├── Ordering.Domain.csproj │ │ ├── Orders │ │ │ └── Order.cs │ │ └── OutBoxMessages │ │ │ └── OutBoxMessage.cs │ ├── Ordering.IGrain │ │ ├── IOrderGrain.cs │ │ └── Ordering.IGrain.csproj │ ├── Ordering.Infrastructure │ │ ├── ApplicationStartup.cs │ │ ├── Database │ │ │ └── OrderDbContext.cs │ │ ├── Extensions │ │ │ └── OrderExtensions.cs │ │ ├── Ordering.Infrastructure.csproj │ │ ├── OutBoxMessageInterceptor │ │ │ └── CreateOrderInterceptor.cs │ │ └── Repositories │ │ │ ├── Orders │ │ │ ├── IReadOrderRepository.cs │ │ │ ├── IWriteOrderRepository.cs │ │ │ ├── OrderReadRepository.cs │ │ │ └── OrderWriteRepository.cs │ │ │ └── OutBox │ │ │ ├── IReadOutBoxMessageRepository.cs │ │ │ ├── IWriteOutBoxMessageRepository.cs │ │ │ ├── ReadOutBoxMessageRepository.cs │ │ │ └── WriteOutBoxMessageRepository.cs │ └── Ordering.WebApi │ │ ├── BackServices │ │ └── OubtBox │ │ │ └── CreateOrderbService.cs │ │ ├── Const.cs │ │ ├── Controllers │ │ └── OrderController.cs │ │ ├── Filters │ │ └── AsyncAuthorizationFilterAttribute.cs │ │ ├── GrpcService │ │ └── GrpcOrderService.cs │ │ ├── Ordering.WebApi.csproj │ │ ├── Program.cs │ │ ├── Properties │ │ └── launchSettings.json │ │ ├── Services │ │ ├── Grains │ │ │ └── OrderGrain.cs │ │ └── Orders │ │ │ ├── IOrderService.cs │ │ │ └── OrderService.cs │ │ ├── appsettings.Development.json │ │ ├── appsettings.json │ │ └── sql │ │ └── order.service.sql └── Paying.Service │ ├── Paying.Domain │ └── Paying.Domain.csproj │ ├── Paying.Infrastructure │ └── Paying.Infrastructure.csproj │ └── Paying.WebApi │ ├── BackServices │ └── PayTimeoutService.cs │ ├── Const.cs │ ├── Controllers │ └── PayController.cs │ ├── Database │ ├── Payment.cs │ └── PaymentContext.cs │ ├── Dtos │ └── CreateOrderEvent.cs │ ├── Paying.WebApi.csproj │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Services │ ├── IPayingService.cs │ └── PayingService.cs │ ├── appsettings.Development.json │ └── appsettings.json ├── Test ├── GrpcHttpService │ ├── JwtAuthApp.Server │ │ ├── Authentication │ │ │ └── JwtTokenService.cs │ │ ├── Controllers │ │ │ └── WeatherForecastController.cs │ │ ├── GrpcService │ │ │ └── AccountService.cs │ │ ├── JwtAuthApp.Server.csproj │ │ ├── Program.cs │ │ ├── Properties │ │ │ └── launchSettings.json │ │ ├── WeatherForecast.cs │ │ ├── appsettings.Development.json │ │ └── appsettings.json │ ├── Login.Client │ │ ├── Controllers │ │ │ └── LoginController.cs │ │ ├── GrpcClient │ │ │ └── LoginClientFactory.cs │ │ ├── HtppClient │ │ │ └── WeatherforecastApi.cs │ │ ├── Login.Client.csproj │ │ ├── Program.cs │ │ ├── Properties │ │ │ └── launchSettings.json │ │ ├── WeatherForecast.cs │ │ ├── appsettings.Development.json │ │ └── appsettings.json │ ├── Login.Client002 │ │ ├── Controllers │ │ │ └── LoginController.cs │ │ ├── GrpcClient │ │ │ └── LoginClientFactory.cs │ │ ├── Login.Client002.csproj │ │ ├── Program.cs │ │ ├── Properties │ │ │ └── launchSettings.json │ │ ├── appsettings.Development.json │ │ └── appsettings.json │ └── MicroService.Shared │ │ ├── GrpcPool │ │ ├── GrpcClientPool.cs │ │ └── IGrpcClientFactory.cs │ │ ├── IAccountService.cs │ │ └── MicroService.Shared.csproj └── UnitTest │ ├── GlobalUsings.cs │ ├── UnitTest.csproj │ └── UnitTest1.cs ├── WebClient ├── Program.cs ├── Properties │ └── launchSettings.json ├── WebClient.csproj ├── appsettings.Development.json ├── appsettings.json └── wwwroot │ ├── img │ └── Login.png │ ├── index.html │ ├── login.html │ ├── order.html │ ├── orderDetail.html │ └── product.html ├── WebSocket.Server ├── Extensions │ └── WebSocketExtensions.cs ├── Handler │ └── WebSocketHandler.cs ├── Manager │ └── WebSocketConnectionManager.cs ├── Middleware │ └── WebSocketManagerMiddleware.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Services │ ├── ProductListHandler.cs │ └── TimeHandler.cs ├── Startup.cs ├── WebScoket.Server.csproj ├── appsettings.Development.json └── appsettings.json ├── efcore-template.sln ├── project ├── App_Data │ ├── dbo.Customer.sql │ └── dbo.Product.sql ├── Attributes │ ├── FormatResponseAttribute.cs │ └── NoFormatResponseAttribute.cs ├── Context │ └── ApplicationDbContext.cs ├── Controllers │ ├── CustomerController.cs │ ├── HomeController.cs │ └── ProductController.cs ├── Dapper │ └── CustomerDal.cs ├── Dtos │ ├── Customer │ │ └── CreateCustomerDto.cs │ └── Product │ │ ├── CreateProductDto.cs │ │ └── PageProductDto.cs ├── Elasticsearchs │ └── Product │ │ ├── Parameters │ │ └── EsProductParameter.cs │ │ └── Search │ │ └── EsProductContext.cs ├── Extensions │ ├── DatabaseExtensions.cs │ ├── DistributedLockExtentions.cs │ ├── ElasticSearchExtensions.cs │ ├── MqExtensions.cs │ ├── RedisExtensions.cs │ └── WatchDogExtensions.cs ├── Filters │ ├── BaseActionFilter.cs │ ├── FilterExtensions.cs │ ├── GlobalExceptionFilter.cs │ └── ValidFilter.cs ├── Models │ ├── Common │ │ ├── IEntity.cs │ │ └── MethodType.cs │ ├── Customer.cs │ ├── CustomerProfile.cs │ ├── Product.cs │ └── ProductProfile.cs ├── Options │ └── SlipExpirationRateLimitOptions.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Repositories │ ├── IReadProductRepository.cs │ ├── IWriteProductRepository.cs │ ├── ProductReadRepository.cs │ └── ProductWriteRepository.cs ├── SeedWork │ └── DatabaseStartup.cs ├── Services │ ├── Customer │ │ ├── CustomerService.cs │ │ └── ICustomerService.cs │ ├── IProductService.cs │ └── ProductService.cs ├── Utility │ ├── BaseController │ │ └── AbsEfWorkController.cs │ └── Helper │ │ ├── CacheHelper.cs │ │ └── TimestampHelper.cs ├── appsettings.Development.json ├── appsettings.json ├── obj │ ├── Debug │ │ └── net7.0 │ │ │ ├── .NETCoreApp,Version=v7.0.AssemblyAttributes.cs │ │ │ ├── project.GlobalUsings.g.cs │ │ │ └── project.assets.cache │ ├── project.assets.json │ ├── project.csproj.nuget.dgspec.json │ ├── project.csproj.nuget.g.props │ └── project.csproj.nuget.g.targets ├── project.csproj ├── watchlogs-log.db └── watchlogs.db ├── readme.md ├── readmeimg ├── Snipaste_2024-01-12_13-22-07.png ├── Snipaste_2024-01-12_13-22-35.png ├── Snipaste_2024-01-12_13-27-45.png ├── image-1.png ├── image-2.png ├── image-3.png ├── image-4.png ├── image-5.png ├── image-6.png ├── image-7.png └── image.png └── 用到的docker.txt /.dockerignore: -------------------------------------------------------------------------------- 1 | **/.classpath 2 | **/.dockerignore 3 | **/.env 4 | **/.git 5 | **/.gitignore 6 | **/.project 7 | **/.settings 8 | **/.toolstarget 9 | **/.vs 10 | **/.vscode 11 | **/*.*proj.user 12 | **/*.dbmdl 13 | **/*.jfm 14 | **/azds.yaml 15 | **/bin 16 | **/charts 17 | **/docker-compose* 18 | **/Dockerfile* 19 | **/node_modules 20 | **/npm-debug.log 21 | **/obj 22 | **/secrets.dev.yaml 23 | **/values.dev.yaml 24 | LICENSE 25 | README.md -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.vs/ProjectEvaluation/chatgptwriteproject.metadata.v5.2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/ProjectEvaluation/chatgptwriteproject.metadata.v5.2 -------------------------------------------------------------------------------- /.vs/ProjectEvaluation/chatgptwriteproject.projects.v5.2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/ProjectEvaluation/chatgptwriteproject.projects.v5.2 -------------------------------------------------------------------------------- /.vs/ProjectEvaluation/efcore开发模板.metadata.v5.2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/ProjectEvaluation/efcore开发模板.metadata.v5.2 -------------------------------------------------------------------------------- /.vs/ProjectEvaluation/efcore开发模板.metadata.v6.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/ProjectEvaluation/efcore开发模板.metadata.v6.1 -------------------------------------------------------------------------------- /.vs/ProjectEvaluation/efcore开发模板.projects.v5.2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/ProjectEvaluation/efcore开发模板.projects.v5.2 -------------------------------------------------------------------------------- /.vs/ProjectEvaluation/efcore开发模板.projects.v6.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/ProjectEvaluation/efcore开发模板.projects.v6.1 -------------------------------------------------------------------------------- /.vs/chatgptwriteproject/FileContentIndex/4bf11d2b-44ab-4b75-aea4-ffcd695276db.vsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/chatgptwriteproject/FileContentIndex/4bf11d2b-44ab-4b75-aea4-ffcd695276db.vsidx -------------------------------------------------------------------------------- /.vs/chatgptwriteproject/FileContentIndex/79b9260d-e5f6-40d1-8fa9-0a240061f98c.vsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/chatgptwriteproject/FileContentIndex/79b9260d-e5f6-40d1-8fa9-0a240061f98c.vsidx -------------------------------------------------------------------------------- /.vs/chatgptwriteproject/FileContentIndex/b6c1578a-dbbe-4dfa-85a3-df3fbf570913.vsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/chatgptwriteproject/FileContentIndex/b6c1578a-dbbe-4dfa-85a3-df3fbf570913.vsidx -------------------------------------------------------------------------------- /.vs/chatgptwriteproject/FileContentIndex/c4ab6445-363d-44b8-89ae-3e5bbbdee3d6.vsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/chatgptwriteproject/FileContentIndex/c4ab6445-363d-44b8-89ae-3e5bbbdee3d6.vsidx -------------------------------------------------------------------------------- /.vs/chatgptwriteproject/FileContentIndex/read.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/chatgptwriteproject/FileContentIndex/read.lock -------------------------------------------------------------------------------- /.vs/efcore-template/DesignTimeBuild/.dtbcache.v2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/efcore-template/DesignTimeBuild/.dtbcache.v2 -------------------------------------------------------------------------------- /.vs/efcore-template/v17/.futdcache.v2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/efcore-template/v17/.futdcache.v2 -------------------------------------------------------------------------------- /.vs/efcore-template/v17/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/efcore-template/v17/.suo -------------------------------------------------------------------------------- /.vs/efcore开发模板/DesignTimeBuild/.dtbcache.v2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/efcore开发模板/DesignTimeBuild/.dtbcache.v2 -------------------------------------------------------------------------------- /.vs/efcore开发模板/FileContentIndex/4c1d815d-a3c4-4549-8ac6-ee9f6fd19fd0.vsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/efcore开发模板/FileContentIndex/4c1d815d-a3c4-4549-8ac6-ee9f6fd19fd0.vsidx -------------------------------------------------------------------------------- /.vs/efcore开发模板/FileContentIndex/5e881f66-3f98-4c71-827d-8cac41b858be.vsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/efcore开发模板/FileContentIndex/5e881f66-3f98-4c71-827d-8cac41b858be.vsidx -------------------------------------------------------------------------------- /.vs/efcore开发模板/FileContentIndex/62cf10e2-c775-4d9c-8a60-b0e7a50ede24.vsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/efcore开发模板/FileContentIndex/62cf10e2-c775-4d9c-8a60-b0e7a50ede24.vsidx -------------------------------------------------------------------------------- /.vs/efcore开发模板/FileContentIndex/read.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/efcore开发模板/FileContentIndex/read.lock -------------------------------------------------------------------------------- /.vs/efcore开发模板/v17/.futdcache.v2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/efcore开发模板/v17/.futdcache.v2 -------------------------------------------------------------------------------- /.vs/efcore开发模板/v17/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/.vs/efcore开发模板/v17/.suo -------------------------------------------------------------------------------- /Common.Cache/Common.Cache.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Common.Cache/Options/CacheOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Common.Cache 8 | { 9 | /// 10 | /// 缓存配置 11 | /// 12 | public class CacheOptions 13 | { 14 | /// 15 | /// 缓存类型 16 | /// 17 | public CacheTypes CacheType { get; set; } 18 | 19 | /// 20 | /// Redis连接字符串 21 | /// 配置参考 https://stackexchange.github.io/StackExchange.Redis/Configuration.html 22 | /// 23 | public string RedisConnectionString { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Common.Cache/Options/CacheType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Common.Cache 8 | { 9 | /// 10 | /// 缓存类型 11 | /// 12 | public enum CacheTypes 13 | { 14 | /// 15 | /// 使用内存缓存(不支持分布式) 16 | /// 17 | InMemory = 0, 18 | 19 | /// 20 | /// 使用Redis缓存(支持分布式) 21 | /// 22 | Redis = 1 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Common.DapperDal/Common.DapperDal.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Common.DapperDal/DalBaseOfTEntity.Get.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using System.Text; 6 | 7 | namespace DapperDal 8 | { 9 | public partial class DalBase where TEntity : class 10 | { 11 | /// 12 | /// 根据实体ID(主键)获取实体 13 | /// 14 | /// 实体ID 15 | /// 实体 16 | public virtual Task Get(TPrimaryKey id) 17 | { 18 | using (var connection = OpenConnection()) 19 | { 20 | return Configuration.DalImplementor.Get( 21 | connection: connection, 22 | id: id, 23 | transaction: null, 24 | commandTimeout: null); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Common.DapperDal/DalBaseOfTEntity.Insert.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using System.Text; 6 | 7 | namespace DapperDal 8 | { 9 | public partial class DalBase where TEntity : class 10 | { 11 | /// 12 | /// 插入指定实体 13 | /// 14 | /// 实体 15 | /// 实体主键 16 | public virtual async Task Insert(TEntity entity) 17 | { 18 | using (var connection = OpenConnection()) 19 | { 20 | return await Configuration.DalImplementor.Insert( 21 | connection: connection, 22 | entity: entity, 23 | transaction: null, 24 | commandTimeout: null); 25 | } 26 | } 27 | 28 | /// 29 | /// 批量插入指定实体集合 30 | /// 31 | /// 实体集合 32 | public virtual Task Insert(IEnumerable entities) 33 | { 34 | using (var connection = OpenConnection()) 35 | { 36 | return Configuration.DalImplementor.Insert( 37 | connection: connection, 38 | entities: entities, 39 | transaction: null, 40 | commandTimeout: null); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Common.DapperDal/DalBaseOfTEntity.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/Common.DapperDal/DalBaseOfTEntity.cs -------------------------------------------------------------------------------- /Common.DapperDal/DalOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DapperDal 4 | { 5 | /// 6 | /// 数据访问设置项 7 | /// 8 | public class DalOptions 9 | { 10 | /// 11 | /// 逻辑删除时更新属性和值的构造器 12 | /// 13 | public Func SoftDeletePropsFactory { get; set; } 14 | 15 | /// 16 | /// 逻辑激活时更新属性和值的构造器 17 | /// 18 | public Func SoftActivePropsFactory { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Common.DapperDal/Expressions/PredicateExtensions.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/alexfoxgill/ExpressionTools 2 | 3 | using System; 4 | using System.Linq.Expressions; 5 | using DapperDal.Predicate; 6 | 7 | namespace DapperDal.Expressions 8 | { 9 | /// 10 | /// 查询条件表达式转换扩展 11 | /// 12 | public static class PredicateExtensions 13 | { 14 | /// 15 | /// 查询条件表达式转换为谓词组的扩展方法 16 | /// 17 | /// 实体类型 18 | /// 实体主键类型 19 | /// 查询条件表达式 20 | /// 查询条件谓词组 21 | public static IPredicate ToPredicateGroup( 22 | this Expression> expression) where TEntity : class 23 | { 24 | if (expression == null) 25 | { 26 | return null; 27 | } 28 | 29 | if (ExpressionUtility.IsConstant(expression, true)) 30 | { 31 | return null; 32 | } 33 | 34 | if (ExpressionUtility.IsConstant(expression, false)) 35 | { 36 | return null; 37 | } 38 | 39 | IPredicate pg = QueryBuilder.FromExpression(expression); 40 | 41 | return pg; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Common.DapperDal/Expressions/QueryFunctions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DapperDal.Expressions 4 | { 5 | /// 6 | /// 映射SQL查询支持的函数 7 | /// 8 | public static class QueryFunctions 9 | { 10 | /// 11 | /// For reflection only. 12 | /// 13 | /// 14 | /// 15 | /// 16 | public static bool Like(string pattern, object member) 17 | { 18 | throw new InvalidOperationException("For reflection only!"); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Common.DapperDal/Expressions/SortDirection.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/Common.DapperDal/Expressions/SortDirection.cs -------------------------------------------------------------------------------- /Common.DapperDal/Mapper/AutoClassMapper.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/Common.DapperDal/Mapper/AutoClassMapper.cs -------------------------------------------------------------------------------- /Common.DapperDal/Mapper/PluralizedAutoClassMapper.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/Common.DapperDal/Mapper/PluralizedAutoClassMapper.cs -------------------------------------------------------------------------------- /Common.DistributedId/AsyncHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Common.DistributedId 9 | { 10 | internal static class AsyncHelper 11 | { 12 | private static readonly TaskFactory _myTaskFactory =new TaskFactory(CancellationToken.None,TaskCreationOptions.None,TaskContinuationOptions.None,TaskScheduler.Default); 13 | 14 | public static void RunSync(Func func) 15 | { 16 | _myTaskFactory.StartNew(func).Unwrap().GetAwaiter().GetResult(); 17 | } 18 | 19 | public static TResult RunSync(Func> func) 20 | { 21 | return _myTaskFactory.StartNew(func).Unwrap().GetAwaiter().GetResult(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Common.DistributedId/Common.DistributedId.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Common.DistributedId/DistributedIdOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Common.DistributedId 8 | { 9 | /// 10 | /// 分布式Id选项 11 | /// 12 | public class DistributedIdOptions 13 | { 14 | public SequentialGuidType GuidType { get; set; } = SequentialGuidType.AtBegin; 15 | 16 | /// 17 | /// 指定机器Id,范围1-1023,若不指定则在范围内随机取 18 | /// 19 | public int WorkerId { get; set; } 20 | /// 21 | /// 是否为分布式(即多实例部署) 22 | /// 若开启则需要提前配置分布式缓存(Cache)与分布式锁(DistributedLock) 23 | /// 多实例部署并且使用LongId(即雪花Id)时建议开启此选项 24 | /// 25 | public bool Distributed { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Common.DistributedId/IDistributedId.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Common.DistributedId 8 | { 9 | /// 10 | /// 分布式Id 11 | /// 12 | public interface IDistributedId 13 | { 14 | /// 15 | /// 生成有序Guid,使用默认排序类型 16 | /// 17 | /// 18 | Guid NewGuid(); 19 | /// 20 | /// 生成有序Guid,指定排序类型 21 | /// 22 | /// 排序类型 23 | /// 24 | Guid NewGuid(SequentialGuidType sequentialGuidType); 25 | /// 26 | /// 生成有序雪花Id 27 | /// 28 | /// 29 | long NewLongId(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Common.DistributedId/Snowflake/DisposableAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Common.DistributedId 8 | { 9 | public class DisposableAction:IDisposable 10 | { 11 | readonly Action _action; 12 | public DisposableAction(Action action)=>_action = action?? throw new ArgumentNullException("action"); 13 | 14 | public void Dispose() => _action(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Common.DistributedId/Snowflake/InvalidSystemClock.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Common.DistributedId 8 | { 9 | internal class InvalidSystemClock:Exception 10 | { 11 | public InvalidSystemClock(string message):base(message) { } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Common.DistributedId/Snowflake/TImeExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Common.DistributedId 8 | { 9 | internal class System 10 | { 11 | public static Func currentTimeFunc = InternalCurrentTimeMillis; 12 | 13 | public static long CurrentTimeMillis()=>currentTimeFunc(); 14 | public static IDisposable StubCurrentTime(long millis) 15 | { 16 | currentTimeFunc = () => millis; 17 | return new DisposableAction(() => currentTimeFunc = InternalCurrentTimeMillis); 18 | } 19 | private static long InternalCurrentTimeMillis() 20 | { 21 | return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds; 22 | } 23 | 24 | public static readonly DateTime Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Common.DistributedLock.Abstractions/Common.DistributedLock.Abstractions.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Common.DistributedLock.Abstractions/DistributedLockOptions.cs: -------------------------------------------------------------------------------- 1 | namespace DistributedLock.Abstractions 2 | { 3 | public class DistributedLockOptions 4 | { 5 | public LockType LockType { get; set; } = LockType.InMemory; 6 | public string[]? RedisEndPoints { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /Common.DistributedLock.Abstractions/IDistributedLock.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DistributedLock.Abstractions 8 | { 9 | public interface IDistributedLock 10 | { 11 | Task Lock(string key,TimeSpan? timeout = null); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Common.DistributedLock.Abstractions/LockType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DistributedLock.Abstractions 8 | { 9 | /// 10 | /// 分布式锁类型 11 | /// 12 | public enum LockType 13 | { 14 | /// 15 | /// 内存实现(进程内有效) 16 | /// 17 | InMemory = 1, 18 | /// 19 | /// Redis实现(分布式) 20 | /// 21 | Redis =2 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Common.DistributedLock.InMemory/Common.DistributedLock.InMemory.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Common.DistributedLock.InMemory/InMemoryDistributedLock.cs: -------------------------------------------------------------------------------- 1 | using AsyncKeyedLock; 2 | using DistributedLock.Abstractions; 3 | 4 | namespace DistributedLock.InMemory 5 | { 6 | public class InMemoryDistributedLock : IDistributedLock 7 | { 8 | private readonly StripedAsyncKeyedLocker _asyncKeyedLocker = new(); 9 | public async Task Lock(string key, TimeSpan? timeout = null) 10 | { 11 | timeout = timeout ?? TimeSpan.FromSeconds(10); 12 | 13 | var lockResult = await _asyncKeyedLocker.LockAsync(key, timeout.Value); 14 | if (!lockResult.EnteredSemaphore) 15 | { 16 | throw new TimeoutException($"获取锁超时{timeout.Value.TotalSeconds}秒"); 17 | } 18 | 19 | return lockResult; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Common.DistributedLock.Redis/Common.DistributedLock.Redis.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Common.Es/Common.Es.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Common.Es/Elasticsearchs/Es.Foundation/EsClientExtension.cs: -------------------------------------------------------------------------------- 1 | using Nest; 2 | 3 | namespace Common.Es 4 | { 5 | /// 6 | /// es扩展类 7 | /// 8 | public static class EsClientExtension 9 | { 10 | 11 | public static bool CreateIndex(this ElasticClient elasticClient,string indexName="",int numberOfShards=5,int numberOfReplicas=1) where T : class 12 | { 13 | if (string.IsNullOrWhiteSpace(indexName)) 14 | { 15 | indexName = typeof(T).Name; 16 | } 17 | if(elasticClient.Indices.Exists(indexName).Exists) { return false; } 18 | else 19 | { 20 | var indexState = new IndexState(); 21 | IndexSettings settings = new IndexSettings() 22 | { 23 | NumberOfReplicas = numberOfReplicas, 24 | NumberOfShards = numberOfShards, 25 | }; 26 | var response = elasticClient.Indices.Create(indexName, p => p.InitializeUsing(indexState).Map(p => p.AutoMap())); 27 | return response.Acknowledged; 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Common.Es/Elasticsearchs/Es.Foundation/EsConfig.cs: -------------------------------------------------------------------------------- 1 | using Nest; 2 | using System; 3 | using System.Linq; 4 | 5 | namespace Common.Es 6 | { 7 | public class EsConfig 8 | { 9 | private readonly EsOption _option; 10 | public EsConfig(EsOption option) 11 | { 12 | _option = option; 13 | } 14 | 15 | public ElasticClient GetClient(string indexName = "") 16 | { 17 | if(_option.Urls==null || _option.Urls.Count() == 0) 18 | { 19 | throw new Exception("es 地址不可为空"); 20 | } 21 | //var uris = urls.Select(p => new Uri(p)).ToArray(); 22 | //var connectionPool = new SniffingConnectionPool(uris); 23 | //var connectionSetting = new ConnectionSettings(connectionPool); //单机状态使用集群导致链接docker 的ip导致链接失败报错(该es虚拟机下doker单机部署的) 24 | var uri = new Uri(_option.Urls[0]); 25 | var connectionSettings = new ConnectionSettings(uri).BasicAuthentication(_option.Username, _option.Password); 26 | if (!string.IsNullOrWhiteSpace(_option.Urls[0])) 27 | { 28 | connectionSettings.DefaultIndex(indexName); 29 | } 30 | return new ElasticClient(connectionSettings); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Common.Es/Elasticsearchs/Es.Foundation/EsOption.cs: -------------------------------------------------------------------------------- 1 | namespace Common.Es 2 | { 3 | public class EsOption 4 | { 5 | public string[] Urls { get; set; } 6 | public string Username { get; set; } 7 | public string Password { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Common.Es/Elasticsearchs/Es.Foundation/IEsBase.cs: -------------------------------------------------------------------------------- 1 | namespace Common.Es 2 | { 3 | public interface IEsBase 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Common.Es/Elasticsearchs/Es.Parameters/EsParameter.cs: -------------------------------------------------------------------------------- 1 | namespace Common.Es 2 | { 3 | public class EsPageParameter 4 | { 5 | private const int maxPageSize = 100; 6 | public int PageNumber { get; set; } = 1; 7 | 8 | private int _pageSize = 10; 9 | public int PageSize 10 | { 11 | get => _pageSize; 12 | set => _pageSize = value > maxPageSize ? maxPageSize : value; 13 | } 14 | 15 | public string KeyWords { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Common.Es/Elasticsearchs/Es.Response/EsData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Common.Es 8 | { 9 | public class EsData 10 | { 11 | public long Total { get; set; } 12 | public List List { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Common.Es/Elasticsearchs/Es.Response/EsResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Common.Es 8 | { 9 | public class EsResult 10 | { 11 | public int Code { get; set; } 12 | public string Message { get; set; } 13 | public object Data { get; set; } 14 | public object Metadata { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Common.Grpc/Common.Grpc.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Common.Grpc/GrpcPool/IGrpcClientFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Channels; 6 | using System.Threading.Tasks; 7 | using Grpc.Core; 8 | using Grpc.Net.Client; 9 | 10 | namespace MicroService.Shared.GrpcPool 11 | { 12 | public interface IGrpcClientFactory 13 | { 14 | Tclient Create(GrpcChannel channel); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Common.MessageMiddleware/Factory/IMQFactory.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MessageMiddleware.Factory 9 | { 10 | /// 11 | /// MQ工厂 12 | /// 13 | public interface IMQFactory 14 | { 15 | /// 16 | /// 创建mq对象 17 | /// 18 | /// 19 | /// 20 | public IMQPublisher Create(MQType type); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Common.MessageMiddleware/Factory/MQConfig.cs: -------------------------------------------------------------------------------- 1 | using MessageMiddleware.Kafka.Producers; 2 | using MessageMiddleware.RabbitMQ; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using MessageMiddleware.Kafka.Consumer; 9 | 10 | namespace MessageMiddleware.Factory 11 | { 12 | /// 13 | /// 14 | /// 15 | public class MQConfig 16 | { 17 | /// 18 | /// 使用哪个mq,对应MQType枚举 19 | /// 1:kafka 20 | /// 2:rabbit 21 | /// 22 | public int Use { get; set; } 23 | 24 | public bool PublishLog { get; set; } = true; 25 | /// 26 | /// 27 | /// 28 | public bool ConsumerLog { get; set; } = true; 29 | 30 | /// 31 | /// 生产配置 32 | /// 33 | public ProducerOptions Kafka { get; set; } 34 | 35 | /// 36 | /// rabbit配置 37 | /// 38 | public RabbitMQSetting Rabbit { get; set; } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Common.MessageMiddleware/Factory/MQType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MessageMiddleware.Factory 8 | { 9 | /// 10 | /// MQ枚举类型 11 | /// 12 | public enum MQType 13 | { 14 | Kafka = 1, 15 | Rabbit = 2, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Common.MessageMiddleware/IMQPublisher.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace MessageMiddleware 4 | { 5 | public interface IMQPublisher 6 | { 7 | /// 8 | /// 发送队列消息 9 | /// 10 | /// 11 | /// 12 | /// 13 | /// 14 | /// 15 | /// 16 | /// 序列化方式, 17 | /// 兼容 T 有子类,反序列化问题 18 | /// 19 | /// 20 | bool Publish(T obj, string exchange, string queue = "", string routingKey = "#", JsonSerializerSettings settings = null); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Common.MessageMiddleware/Kafka/BaseOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MessageMiddleware.Kafka 8 | { 9 | public class BaseOptions 10 | { 11 | /// 12 | /// 服务器地址 13 | /// 14 | public string BootstrapServers { get; set; } 15 | 16 | /// 17 | /// SASL PLAINTEXT认证用户名 18 | /// 19 | public string SaslUsername { get; set; } 20 | 21 | /// 22 | /// SASL PLAINTEXT认证密码 23 | /// 24 | public string SaslPassword { get; set; } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Common.MessageMiddleware/Kafka/Consumer/ConsumerOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MessageMiddleware.Kafka.Consumer 8 | { 9 | public class ConsumerOptions : BaseOptions 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Common.MessageMiddleware/Kafka/Producers/IKafkaProduce.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MessageMiddleware.Kafka.Producers 8 | { 9 | public interface IKafkaProduce 10 | { 11 | Task PublishAsync(string topic, TMessage message) where TMessage : class; 12 | Task PublishAsync(string topic,string key, TMessage message) where TMessage : class; 13 | 14 | Task PublishAsync(string topic, string message); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Common.MessageMiddleware/Kafka/Producers/ProducerOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MessageMiddleware.Kafka.Producers 8 | { 9 | public class ProducerOptions : BaseOptions 10 | { 11 | /// 12 | /// 键值 13 | /// 14 | public string Key { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Common.MessageMiddleware/ListenerConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MessageMiddleware 8 | { 9 | /// 10 | /// 监听对象 11 | /// 12 | public class ListenerConfig 13 | { 14 | public string Queue { get; set; } 15 | public string Exchange { get; set; } 16 | public string RoutingKey { get; set; } 17 | public Func> OnReceivedHandle; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Common.MessageMiddleware/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "MessageMiddleware": { 4 | "commandName": "Project", 5 | "launchBrowser": true, 6 | "environmentVariables": { 7 | "ASPNETCORE_ENVIRONMENT": "Development" 8 | }, 9 | "applicationUrl": "https://localhost:55549;http://localhost:55550" 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Common.MessageMiddleware/RabbitMQ/IRabbitMQConnection.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | 3 | namespace MessageMiddleware.RabbitMQ 4 | { 5 | public interface IRabbitMQConnection 6 | { 7 | IConnection GetConnection(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Common.MessageMiddleware/RabbitMQ/RabbitMQChannelPooledObjectPolicy.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging; 2 | using Microsoft.Extensions.ObjectPool; 3 | using RabbitMQ.Client; 4 | using System; 5 | 6 | namespace MessageMiddleware.RabbitMQ 7 | { 8 | public class RabbitMQChannelPooledObjectPolicy : IPooledObjectPolicy 9 | { 10 | private readonly IRabbitMQConnection _connection; 11 | private readonly ILogger _logger; 12 | 13 | public RabbitMQChannelPooledObjectPolicy(IRabbitMQConnection connection, ILogger logger) 14 | { 15 | _connection = connection; 16 | _logger = logger; 17 | } 18 | 19 | public IModel Create() 20 | { 21 | try 22 | { 23 | return _connection.GetConnection().CreateModel(); 24 | } 25 | catch (Exception e) 26 | { 27 | _logger.LogError(e, "RabbitMQ Create Model Fail!"); 28 | throw; 29 | } 30 | } 31 | 32 | public bool Return(IModel obj) 33 | { 34 | if (obj.IsOpen) 35 | { 36 | return true; 37 | } 38 | 39 | obj?.Dispose(); 40 | return false; 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /Common.MessageMiddleware/RabbitMQ/RabbitMQSetting.cs: -------------------------------------------------------------------------------- 1 | namespace MessageMiddleware.RabbitMQ 2 | { 3 | public class RabbitMQSetting 4 | { 5 | /// 6 | /// 链接地址 7 | /// 8 | public string[] ConnectionString { get; set; } 9 | /// 10 | /// 账号 11 | /// 12 | public string UserName { get; set; } 13 | /// 14 | /// 密码 15 | /// 16 | public string Password { get; set; } 17 | /// 18 | /// 端口 19 | /// 20 | public int Port { get; set; } 21 | 22 | public bool SslEnabled { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Common.MessageMiddleware/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using Microsoft.Extensions.DependencyInjection.Extensions; 3 | using MessageMiddleware.RabbitMQ; 4 | using System; 5 | 6 | namespace MessageMiddleware 7 | { 8 | public static class ServiceCollectionExtensions 9 | { 10 | public static IServiceCollection UseRabbitMQ(this IServiceCollection services, Func setting) 11 | { 12 | services.AddSingleton(setting.Invoke()); 13 | services.AddSingleton(); 14 | 15 | services.AddSingleton(); 16 | 17 | return services; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Common.MessageMiddleware/configs/mqsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "mqsetting": { 3 | "use": 2, //1 代表kafka,2 代表Rabbit 4 | "publishLog": true, 5 | "consumerLog":true, 6 | "kafka": { 7 | "BootstrapServers": "localhost:9092", 8 | "Key": "kafka", 9 | "SaslUsername": "", 10 | "SaslPassword": "" 11 | }, 12 | "Rabbit": { 13 | "ConnectionString": [ "amqps://xx:5671" ], 14 | "UserName": "test", 15 | "PassWord": "test", 16 | "Port": 5671, 17 | "SslEnabled": true 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Common.MessageMiddleware/configs/rabbitmq.json: -------------------------------------------------------------------------------- 1 | { 2 | "connectionString": [ "amqps://xx:5671" ], 3 | "userName": "test", 4 | "password": "tests", 5 | "Port": 5671, 6 | "SslEnabled": true 7 | } -------------------------------------------------------------------------------- /Common.MongoDb/Common.MongoDb.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Common.MongoDb/MongoDbOptions.cs: -------------------------------------------------------------------------------- 1 | namespace MongoDb 2 | { 3 | public class MongoDbOptions 4 | { 5 | public string Connection { get; set; } 6 | public string DataBase { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /Common.MongoDb/MongoDbServiceCoolectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Configuration; 2 | using Microsoft.Extensions.DependencyInjection; 3 | 4 | namespace MongoDb 5 | { 6 | public static class MongoDbServiceCoolectionExtensions 7 | { 8 | /// 9 | /// 添加MongoDb 10 | /// 11 | /// 12 | /// 13 | public static void AddMongoDb(this IServiceCollection services, IConfigurationSection section) 14 | { 15 | services.Configure(options => 16 | { 17 | options.Connection = section.GetSection("ConnectionString").Value??throw new ArgumentNullException("mongodb connection isnull"); 18 | options.DataBase = section.GetSection("DataBase").Value ?? throw new ArgumentNullException("mongodb database isnull"); 19 | }); 20 | services.AddScoped(); 21 | } 22 | // 获取MongoDbOptions配置节 23 | //IConfigurationSection section = configuration.GetSection("MongoDbOptions"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Common.Redis/Configuration/RedisHost.cs: -------------------------------------------------------------------------------- 1 | namespace Common.Redis.Extensions.Configuration 2 | { 3 | /// 4 | /// redis host 5 | /// 6 | public class RedisHost 7 | { 8 | /// 9 | /// 主机名 10 | /// 11 | public string Host { get; set; } = "localhost"; 12 | /// 13 | /// 端口 14 | /// 15 | public int Port { get; set; } = 6379; 16 | } 17 | } -------------------------------------------------------------------------------- /Common.Redis/Configuration/ServerEnumerationStrategy.cs: -------------------------------------------------------------------------------- 1 | namespace Common.Redis.Extensions.Configuration 2 | { 3 | public partial class ServerEnumerationStrategy 4 | { 5 | public enum ModeOptions 6 | { 7 | All = 0, 8 | Single 9 | } 10 | 11 | public enum TargetRoleOptions 12 | { 13 | Any = 0, 14 | PreferSlave 15 | } 16 | 17 | public enum UnreachableServerActionOptions 18 | { 19 | Throw = 0, 20 | IgnoreIfOtherAvailable 21 | } 22 | 23 | //[ConfigurationProperty("mode", IsRequired = false, DefaultValue = "All")] 24 | 25 | /// 26 | /// Specify the strategy mode 27 | /// 28 | /// 29 | /// Default value All. 30 | /// 31 | public ModeOptions Mode { get; set; } 32 | 33 | /// 34 | /// Specify the target role 35 | /// 36 | /// 37 | /// Default value Any. 38 | /// 39 | public TargetRoleOptions TargetRole { get; set; } 40 | 41 | /// 42 | /// Specify the unreachable server action 43 | /// 44 | /// 45 | /// Default value Throw. 46 | /// 47 | public UnreachableServerActionOptions UnreachableServerAction { get; set; } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Common.Redis/Extensions/LinqExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Common.Redis.Extensions.Extensions 7 | { 8 | 9 | /// 10 | /// Adds behavior to System.Linq. 11 | /// 12 | public static class LinqExtensions 13 | { 14 | /// 15 | /// Eaches the specified enumeration. 16 | /// 17 | /// 18 | /// The enumeration. 19 | /// The action. 20 | public static void ForEach(this IEnumerable source, Action action) 21 | { 22 | foreach (T item in source) 23 | { 24 | action(item); 25 | } 26 | } 27 | 28 | /// 29 | /// Fors the each asynchronous. 30 | /// 31 | /// 32 | /// The source. 33 | /// The body. 34 | /// 35 | public static Task ForEachAsync(this IEnumerable source, Func body) 36 | { 37 | return Task.WhenAll( 38 | from item in source 39 | select Task.Run(() => body(item))); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Common.Redis/Serializer/SerializerEnum.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Common.Redis.Extensions.Serializer 6 | { 7 | /// 8 | /// 序列化类型 9 | /// 10 | public enum SerializerEnum 11 | { 12 | /// 13 | /// json序列化 14 | /// 15 | JSON, 16 | /// 17 | /// bson序列化 18 | /// 19 | BSON, 20 | /// 21 | /// protobuf序列化 22 | /// 23 | PROTOBUF 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Common.Redis/ServerIteration/ServerIteratorFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Common.Redis.Extensions.Configuration; 5 | using StackExchange.Redis; 6 | 7 | namespace Common.Redis.Extensions.ServerIteration 8 | { 9 | public static class ServerIteratorFactory 10 | { 11 | public static IEnumerable GetServers( 12 | ConnectionMultiplexer multiplexer, 13 | ServerEnumerationStrategy serverEnumerationStrategy) 14 | { 15 | switch (serverEnumerationStrategy.Mode) 16 | { 17 | case ServerEnumerationStrategy.ModeOptions.All: 18 | var serversAll = new ServerEnumerable(multiplexer, 19 | serverEnumerationStrategy.TargetRole, 20 | serverEnumerationStrategy.UnreachableServerAction); 21 | return serversAll; 22 | 23 | case ServerEnumerationStrategy.ModeOptions.Single: 24 | var serversSingle = new ServerEnumerable(multiplexer, 25 | serverEnumerationStrategy.TargetRole, 26 | serverEnumerationStrategy.UnreachableServerAction); 27 | return serversSingle.Take(1); 28 | 29 | default: 30 | throw new NotImplementedException(); 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Common.RepositoryComponent/BaseRepo/IWriteRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Linq.Expressions; 2 | 3 | namespace RepositoryComponent.BaseRepo 4 | { 5 | public interface IWriteRepository where TEntity : class 6 | { 7 | //void Add(TEntity entity); 8 | //void Update(TEntity entity); 9 | //void Delete(TEntity entity); 10 | //void Add(List entity); 11 | //void Update(List entity); 12 | //void Delete(List entity); 13 | 14 | //IUnitOfWork GetUnitOfWork { get; } 15 | Task SaveChangeAsync(CancellationToken cancellationToken = default); 16 | #region Add 17 | 18 | ValueTask AddAsync(TEntity entity, CancellationToken cancellationToken = default); 19 | 20 | Task AddRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default); 21 | 22 | #endregion 23 | 24 | #region Update 25 | 26 | Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default); 27 | 28 | Task UpdateRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default); 29 | 30 | #endregion 31 | 32 | #region Remove 33 | 34 | Task RemoveAsync(TEntity entity, CancellationToken cancellationToken = default); 35 | 36 | Task RemoveRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default); 37 | 38 | Task RemoveAsync(Expression> predicate, CancellationToken cancellationToken = default); 39 | 40 | #endregion 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Common.RepositoryComponent/Common.RepositoryComponent.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Common.RepositoryComponent/DbFactories/DbFactory.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using System.Data; 3 | 4 | namespace RepositoryComponent.DbFactories 5 | { 6 | public class DbFactory:IDisposable where Ctx : DbContext 7 | { 8 | private bool _disposed; 9 | private Func _instanceFunc; 10 | //private DbContextType _dbType; 11 | private Ctx _context; 12 | public Ctx Context => _context ?? (_context = _instanceFunc()); 13 | public DbFactory(Func instance 14 | //, DbContextType dbType 15 | ) 16 | { 17 | //_dbType = dbType; 18 | _instanceFunc = instance??throw new ArgumentNullException("dbcontext is null"); 19 | } 20 | 21 | public void Dispose() 22 | { 23 | _disposed = true; 24 | 25 | if (_context != null) 26 | { 27 | _context.Dispose(); 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Common.RepositoryComponent/Page/PaginatedList.cs: -------------------------------------------------------------------------------- 1 | namespace RepositoryComponent.Page 2 | { 3 | public class PaginatedList: PaginatedListBase where TEntity : class 4 | { 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Common.RepositoryComponent/Page/PaginatedListBase.cs: -------------------------------------------------------------------------------- 1 | namespace RepositoryComponent.Page 2 | { 3 | public class PaginatedListBase where TEntity : class 4 | { 5 | public long Total { get; set; } 6 | public int TotalPages { get; set; } 7 | public List Result { get; set; }=default!; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Common.RepositoryComponent/Page/PaginatedOptions.cs: -------------------------------------------------------------------------------- 1 | namespace RepositoryComponent.Page 2 | { 3 | public class PaginatedOptions:RequestPageBase 4 | { 5 | public Dictionary? Sorting { get; set; } 6 | public PaginatedOptions() 7 | { 8 | 9 | } 10 | 11 | public PaginatedOptions(int page, int pageSize, Dictionary? sorting=null) 12 | { 13 | Page = page; 14 | PageSize = pageSize; 15 | Sorting = sorting; 16 | } 17 | 18 | public PaginatedOptions(int page,int pageSize,string sortField,bool isDescending=true): 19 | this(page,pageSize,new Dictionary(new List> 20 | { new(sortField, isDescending) })) 21 | { 22 | 23 | } 24 | } 25 | 26 | public class PaginatedOptions: PaginatedOptions 27 | { 28 | public T Search { get; set; } = default(T); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Common.RepositoryComponent/Page/RequestPageBase.cs: -------------------------------------------------------------------------------- 1 | namespace RepositoryComponent.Page 2 | { 3 | public class RequestPageBase 4 | { 5 | public int Page { get; set; } = 1; 6 | 7 | public int PageSize { get; set; } = 20; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Common.RestSharpClient/ApiException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace RestSharpComponent 8 | { 9 | public class ApiException:Exception 10 | { 11 | public int ErrorCode { get; set; } 12 | public object ErrorContent { get; set; } 13 | public ApiException() 14 | { 15 | 16 | } 17 | public ApiException(int errorCode,string message):base(message) 18 | { 19 | this.ErrorCode = errorCode; 20 | } 21 | public ApiException(int errorCode,string message,object errorContent = null):base(message) 22 | { 23 | this.ErrorCode = errorCode; 24 | this.ErrorContent = errorContent; 25 | 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Common.RestSharpClient/Common.RestSharpClient.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Common.RestSharpClient/ExceptionFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace RestSharpComponent 8 | { 9 | /// 10 | /// A delegate to ExceptionFactory method 11 | /// 12 | /// 13 | /// 14 | /// 15 | public delegate Exception ExceptionFactory(string methodName, IApiResponse response); 16 | } 17 | -------------------------------------------------------------------------------- /Common.RestSharpClient/GateApiException.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.Runtime.Serialization; 3 | 4 | namespace RestSharpComponent 5 | { 6 | [DataContract] 7 | public class GateApiException : ApiException 8 | { 9 | [DataMember(Name ="label",EmitDefaultValue =false)] 10 | public string ErrorLabel { get; set; } 11 | 12 | public string ErrorMessage 13 | { 14 | get { return string.IsNullOrWhiteSpace(this._errorDetail) ? this._errorMessage : this._errorDetail; } 15 | } 16 | [DataMember(Name = "message")] 17 | private string _errorMessage; 18 | 19 | [DataMember(Name = "detail")] 20 | private string _errorDetail; 21 | 22 | 23 | [JsonConstructor] 24 | public GateApiException(string label,string message=default(string),string detail=default(string)) 25 | { 26 | this.ErrorLabel = label; 27 | this._errorMessage = message; 28 | this._errorDetail = detail; 29 | } 30 | 31 | public override string Message => JsonConvert.SerializeObject(this, Formatting.None, new JsonSerializerSettings { NullValueHandling= NullValueHandling.Ignore}); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Common.RestSharpClient/GlobalConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace RestSharpComponent 8 | { 9 | public partial class GlobalConfiguration : Configuration 10 | { 11 | private static readonly object GlobalConfigSync = new { }; 12 | private static IReadableConfiguration _globalConfiguration; 13 | 14 | private GlobalConfiguration() 15 | { 16 | 17 | } 18 | public GlobalConfiguration(IDictionary defaultHeader,string apiV4Key,string apiV4Secret,string basePath = "http://localhost:9001"):base(defaultHeader,apiV4Key,apiV4Secret,basePath) 19 | { 20 | 21 | } 22 | 23 | static GlobalConfiguration() 24 | { 25 | Instance = new GlobalConfiguration(); 26 | } 27 | 28 | public static IReadableConfiguration Instance 29 | { 30 | get 31 | { 32 | return _globalConfiguration; 33 | } 34 | set 35 | { 36 | lock(GlobalConfigSync) 37 | { 38 | _globalConfiguration = value; 39 | } 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Common.RestSharpClient/HttpMethod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace RestSharpComponent 8 | { 9 | /// 10 | /// http emthods supported by swagger 11 | /// 12 | public enum HttpMethod 13 | { 14 | Get, 15 | Post, 16 | Put, 17 | Delete, 18 | Head, 19 | Options, 20 | Patch 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Common.RestSharpClient/IApiAccessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace RestSharpComponent 8 | { 9 | public interface IApiAccessor 10 | { 11 | IReadableConfiguration Configuration { get; set; } 12 | 13 | string GetBasePath(); 14 | 15 | ExceptionFactory ExceptionFactory { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Common.RestSharpClient/IAsynchronousClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace RestSharpComponent 8 | { 9 | public interface IAsynchronousClient 10 | { 11 | Task> GetAsync(string path, RequestOptions options, IReadableConfiguration configuration = null); 12 | Task> PostAsync(string path, RequestOptions options, IReadableConfiguration configuration = null); 13 | Task> PutAsync(string path, RequestOptions options, IReadableConfiguration configuration = null); 14 | Task> DeleteAsync(string path, RequestOptions options, IReadableConfiguration configuration = null); 15 | Task> HeadAsync(string path, RequestOptions options, IReadableConfiguration configuration = null); 16 | Task> OptionsAsync(string path, RequestOptions options, IReadableConfiguration configuration = null); 17 | Task> PatchAsync(string path, RequestOptions options, IReadableConfiguration configuration = null); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Common.RestSharpClient/ISynchronousClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace RestSharpComponent 8 | { 9 | public interface ISynchronousClient 10 | { 11 | ApiResponse Get(string path, RequestOptions options, IReadableConfiguration configuration = null); 12 | ApiResponse Post(string path, RequestOptions options, IReadableConfiguration configuration = null); 13 | ApiResponse Put(string path, RequestOptions options, IReadableConfiguration configuration = null); 14 | ApiResponse Delete(string path, RequestOptions options, IReadableConfiguration configuration = null); 15 | ApiResponse Head(string path, RequestOptions options, IReadableConfiguration configuration = null); 16 | ApiResponse Options(string path, RequestOptions options, IReadableConfiguration configuration = null); 17 | ApiResponse Patch(string path, RequestOptions options, IReadableConfiguration configuration = null); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Common.RestSharpClient/OpenAPIDateConverter.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json.Converters; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace RestSharpComponent 9 | { 10 | public class OpenAPIDateConverter:IsoDateTimeConverter 11 | { 12 | public OpenAPIDateConverter() 13 | { 14 | DateTimeFormat = "yyyy-MM-dd"; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Common.RestSharpClient/RequestOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace RestSharpComponent 10 | { 11 | public class RequestOptions 12 | { 13 | public Dictionary PathParameters { get; set; } 14 | 15 | public Multimap QueryParameters { get; set; } 16 | public Multimap HeaderParameters { get; set; } 17 | public Dictionary FormParameters { get; set; } 18 | public Dictionary FileParameters { get; set; } 19 | public List Cookies { get; set; } 20 | public object Data { get; set; } 21 | public bool RequireApiV4Auth { get; set; } 22 | public RequestOptions() 23 | { 24 | PathParameters = new Dictionary(); 25 | QueryParameters = new Multimap(); 26 | HeaderParameters = new Multimap(); 27 | FormParameters = new Dictionary(); 28 | FileParameters = new Dictionary(); 29 | Cookies = new List(); 30 | RequireApiV4Auth = false; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Common.SqlSugar/Common.SqlSugar.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Common.SqlSugar/Internal/SqlSugarPagedList.cs: -------------------------------------------------------------------------------- 1 | namespace CommonSqlSugar; 2 | 3 | /// 4 | /// 分页泛型集合 5 | /// 6 | /// 7 | public class SqlSugarPagedList 8 | where TEntity : new() 9 | { 10 | /// 11 | /// 页码 12 | /// 13 | public int PageIndex { get; set; } 14 | 15 | /// 16 | /// 页容量 17 | /// 18 | public int PageSize { get; set; } 19 | 20 | /// 21 | /// 总条数 22 | /// 23 | public int TotalCount { get; set; } 24 | 25 | /// 26 | /// 总页数 27 | /// 28 | public int TotalPages { get; set; } 29 | 30 | /// 31 | /// 当前页集合 32 | /// 33 | public IEnumerable Items { get; set; } 34 | 35 | /// 36 | /// 是否有上一页 37 | /// 38 | public bool HasPrevPages { get; set; } 39 | 40 | /// 41 | /// 是否有下一页 42 | /// 43 | public bool HasNextPages { get; set; } 44 | } 45 | 46 | /// 47 | /// 分页集合 48 | /// 49 | public class PagedModel : SqlSugarPagedList 50 | { 51 | } -------------------------------------------------------------------------------- /Common.Util/Common.Util.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Common.Util/Elasticsearchs/Es.Foundation/EsClientExtension.cs: -------------------------------------------------------------------------------- 1 | using Nest; 2 | 3 | namespace Common.Util.Es.Foundation 4 | { 5 | /// 6 | /// es扩展类 7 | /// 8 | public static class EsClientExtension 9 | { 10 | 11 | public static bool CreateIndex(this ElasticClient elasticClient,string indexName="",int numberOfShards=5,int numberOfReplicas=1) where T : class 12 | { 13 | if (string.IsNullOrWhiteSpace(indexName)) 14 | { 15 | indexName = typeof(T).Name; 16 | } 17 | if(elasticClient.Indices.Exists(indexName).Exists) { return false; } 18 | else 19 | { 20 | var indexState = new IndexState(); 21 | IndexSettings settings = new IndexSettings() 22 | { 23 | NumberOfReplicas = numberOfReplicas, 24 | NumberOfShards = numberOfShards, 25 | }; 26 | var response = elasticClient.Indices.Create(indexName, p => p.InitializeUsing(indexState).Map(p => p.AutoMap())); 27 | return response.Acknowledged; 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Common.Util/Elasticsearchs/Es.Foundation/EsConfig.cs: -------------------------------------------------------------------------------- 1 | using Nest; 2 | using System; 3 | using System.Linq; 4 | 5 | namespace Common.Util.Es.Foundation 6 | { 7 | public class EsConfig 8 | { 9 | private readonly EsOption _option; 10 | public EsConfig(EsOption option) 11 | { 12 | _option = option; 13 | } 14 | 15 | public ElasticClient GetClient(string indexName = "") 16 | { 17 | if(_option.Urls==null || _option.Urls.Count() == 0) 18 | { 19 | throw new Exception("es 地址不可为空"); 20 | } 21 | //var uris = urls.Select(p => new Uri(p)).ToArray(); 22 | //var connectionPool = new SniffingConnectionPool(uris); 23 | //var connectionSetting = new ConnectionSettings(connectionPool); //单机状态使用集群导致链接docker 的ip导致链接失败报错(该es虚拟机下doker单机部署的) 24 | var uri = new Uri(_option.Urls[0]); 25 | var connectionSettings = new ConnectionSettings(uri); 26 | if (!string.IsNullOrWhiteSpace(_option.Urls[0])) 27 | { 28 | connectionSettings.DefaultIndex(indexName); 29 | } 30 | return new ElasticClient(connectionSettings); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Common.Util/Elasticsearchs/Es.Foundation/EsOption.cs: -------------------------------------------------------------------------------- 1 | namespace Common.Util.Es.Foundation 2 | { 3 | public class EsOption 4 | { 5 | public string[] Urls { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Common.Util/Elasticsearchs/Es.Foundation/IEsBase.cs: -------------------------------------------------------------------------------- 1 | namespace Common.Util.Es.Foundation 2 | { 3 | public interface IEsBase 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Common.Util/EnumHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Runtime.CompilerServices; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace Common.Util 11 | { 12 | public static class EnumHelper 13 | { 14 | public static string GetDescription(this Enum enums) 15 | { 16 | FieldInfo field = enums.GetType().GetField(enums.ToString()); 17 | 18 | if (field != null) 19 | { 20 | DescriptionAttribute attribute = (DescriptionAttribute)Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)); 21 | 22 | if (attribute != null) 23 | { 24 | return attribute.Description; 25 | } 26 | } 27 | 28 | return enums.ToString(); // 如果没有找到描述,返回枚举成员的名称 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Common.Util/Exceptions/CommonException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Common.Util.Exceptions 8 | { 9 | public abstract class CommonException:Exception 10 | { 11 | public int Code; 12 | public string Msg; 13 | 14 | public CommonException(string message="",int code=0) 15 | { 16 | this.Msg = message; 17 | this.Code = code; 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Common.Util/Exceptions/ParamsErrorException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Common.Util.Exceptions 8 | { 9 | public class ParamsErrorException : CommonException 10 | { 11 | public ParamsErrorException(string msg="参数错误",int code=400):base(msg,code) 12 | { 13 | 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Common.Util/Exceptions/SystemErrorException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Common.Util.Exceptions 8 | { 9 | public class SystemErrorException : CommonException 10 | { 11 | public SystemErrorException(string msg="内部错误,请联系管理员", int code=500) : base(msg, code) 12 | { 13 | 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Common.Util/Jwt/JwtOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Common.Util.Jwt 8 | { 9 | public class JwtOptions 10 | { 11 | public string Secret { get; set; } 12 | public int AccessExpireHours { get; set; } 13 | public int RefreshExpireHours { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Common.Util/Primitives/AjaxResult.cs: -------------------------------------------------------------------------------- 1 | namespace Common.Util.Primitives 2 | { 3 | public class AjaxResult 4 | { 5 | public bool Success { get; set; } = true; 6 | public int ErrorCode { get; set; } 7 | public string Msg { get; set; } 8 | } 9 | 10 | public class AjaxResult : AjaxResult 11 | { 12 | public T Data { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /Common.Util/Primitives/ShowException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Common.Util.Primitives 8 | { 9 | /// 10 | /// 业务异常 11 | /// 不做异常处理,仅为方便返回前端错误提示信息 12 | /// 13 | public class ShowException:Exception 14 | { 15 | public int ErrorCode { get; set; } 16 | 17 | public ShowException() 18 | { 19 | 20 | } 21 | 22 | public ShowException(string message):base(message) 23 | { 24 | 25 | } 26 | 27 | public ShowException(string message,int errorCode) : base(message) 28 | { 29 | ErrorCode = errorCode; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Common.Util/Primitives/TypeExtentions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Common.Util.Primitives 8 | { 9 | /// 10 | /// Type拓展 11 | /// 12 | public static class TypeExtentions 13 | { 14 | /// 15 | /// 是否为简单类型,即JSON序列化时直接ToString 16 | /// 17 | /// 类型 18 | /// 19 | public static bool IsSimple(this Type type) 20 | { 21 | if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) 22 | { 23 | // nullable type, check if the nested type is simple. 24 | return IsSimple(type.GetGenericArguments()[0]); 25 | } 26 | return type.IsPrimitive 27 | || type.IsEnum 28 | || type.Equals(typeof(string)) 29 | || type.Equals(typeof(decimal)) 30 | || type.Equals(typeof(DateTime)) 31 | || type.Equals(typeof(DateTimeOffset)) 32 | || type.Equals(typeof(Guid)) 33 | ; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /ConsumerClient/ConsumerClient.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | Always 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /ConsumerClient/OrderConsumer.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection.Metadata; 2 | using MessageMiddleware; 3 | 4 | namespace ConsumerClient 5 | { 6 | public class OrderConsumer : MQListener 7 | { 8 | public OrderConsumer(IServiceProvider services) : base(services) 9 | { 10 | } 11 | 12 | public override bool Init() 13 | { 14 | Exchange = "xx"; 15 | Queue = "xx"; 16 | return true; 17 | 18 | } 19 | 20 | public override async Task Process(string message) 21 | { 22 | Console.WriteLine($"接收到的消息为:{message}"); 23 | await Task.CompletedTask; 24 | return true; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ConsumerClient/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:30086", 8 | "sslPort": 44321 9 | } 10 | }, 11 | "profiles": { 12 | "http": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "http://localhost:5265", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "https": { 23 | "commandName": "Project", 24 | "dotnetRunMessages": true, 25 | "launchBrowser": true, 26 | "launchUrl": "swagger", 27 | "applicationUrl": "https://localhost:7112;http://localhost:5265", 28 | "environmentVariables": { 29 | "ASPNETCORE_ENVIRONMENT": "Development" 30 | } 31 | }, 32 | "IIS Express": { 33 | "commandName": "IISExpress", 34 | "launchBrowser": true, 35 | "launchUrl": "swagger", 36 | "environmentVariables": { 37 | "ASPNETCORE_ENVIRONMENT": "Development" 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ConsumerClient/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ConsumerClient/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "RabbitMq": { 10 | "connectionString": "amqp://localhost:5672", //多个用;隔开 11 | "userName": "guest", 12 | "password": "guest", 13 | "Port": 5672, 14 | "SslEnabled": false 15 | }, 16 | "MqSetting": { 17 | "Use": 2, //1 代表kafka,2 代表Rabbit 18 | "PublishLog": true, 19 | "ConsumerLog": true, 20 | "Kafka": { 21 | "BootstrapServers": "localhost:9092", 22 | "Key": "kafka", 23 | "SaslUserName": "", 24 | "SaslPassWord": "" 25 | }, 26 | "RabbitMq": { 27 | "ConnectionString": "amqp://localhost:5672", //多个用;隔开 28 | "UserName": "admin", 29 | "Password": "admin", 30 | "Port": 5672, 31 | "SslEnabled": false 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /MicroService/Catalog.Service/Catalogs.Domain/Catalogs.Domain.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /MicroService/Catalog.Service/Catalogs.Domain/Dtos/ProductDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.Json.Serialization; 6 | using System.Threading.Tasks; 7 | 8 | namespace Catalogs.Domain.Dtos 9 | { 10 | public class ProductDto 11 | { 12 | [JsonPropertyName("Id")] 13 | public string Id { get; private set; } 14 | 15 | [JsonPropertyName("Name")] 16 | public string Name { get; private set; } 17 | 18 | [JsonPropertyName("Price")] 19 | public string Price { get; private set; } 20 | 21 | [JsonPropertyName("Stock")] 22 | public string Stock { get; private set; } 23 | 24 | [JsonPropertyName("ImgPath")] 25 | public string ImgPath { get; private set; } 26 | 27 | [JsonPropertyName("Description")] 28 | public string Description { get; private set; } 29 | public ProductDto(string id,string name,string price,string stock,string imgPath,string description="") 30 | { 31 | Id= id; 32 | Name= name; 33 | Price = price; 34 | Stock = stock; 35 | ImgPath= imgPath; 36 | Description= description; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /MicroService/Catalog.Service/Catalogs.Domain/Events/CreateOrderEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Catalogs.Domain.Events 8 | { 9 | public class CreateOrderEvent:IDomainEvent 10 | { 11 | public long EventId { get;set; } 12 | public long UserId { get; private set; } 13 | public long ProductId { get; private set; } 14 | public int Quantity { get;private set; } 15 | public CreateOrderEvent(long EventId, long userId,long productId,int quantity) 16 | { 17 | this.EventId = EventId; 18 | UserId = userId; 19 | ProductId=productId; 20 | Quantity = quantity; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /MicroService/Catalog.Service/Catalogs.Domain/Events/IDomainEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Catalogs.Domain.Events 8 | { 9 | public interface IDomainEvent 10 | { 11 | public long EventId { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /MicroService/Catalog.Service/Catalogs.Domain/Events/IEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Catalogs.Domain.Events 8 | { 9 | public abstract class IEntity 10 | { 11 | private long id; 12 | public virtual long Id 13 | { 14 | get { return id; } 15 | protected set { id = value; } 16 | } 17 | 18 | private List _domainEvents; 19 | public IReadOnlyCollection DomainEvents => _domainEvents?.AsReadOnly(); 20 | 21 | public void AddDomainEvent(IDomainEvent eventItem) 22 | { 23 | _domainEvents = _domainEvents ?? new List(); 24 | _domainEvents.Add(eventItem); 25 | } 26 | public void RemoveDomainEvent(IDomainEvent eventItem) 27 | { 28 | _domainEvents?.Remove(eventItem); 29 | } 30 | public void ClearDomainEvents() 31 | { 32 | _domainEvents?.Clear(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /MicroService/Catalog.Service/Catalogs.Domain/Events/ReceiveCreateOrderEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Catalogs.Domain.Events 8 | { 9 | public class ReceiveCreateOrderEvent 10 | { 11 | public long Id { get; set; } 12 | public string Type { get; set; } 13 | public string Content { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /MicroService/Catalog.Service/Catalogs.Domain/OutBoxMessage/OutBoxMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations.Schema; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Catalogs.Domain.OutBoxMessage 10 | { 11 | [Table("OutBoxMessage")] 12 | public class OutBoxMessage 13 | { 14 | [Key] 15 | [DatabaseGenerated(DatabaseGeneratedOption.None)] // 指定非自增 16 | public long Id { get; set; } 17 | public string Type { get; set; } 18 | public string Content { get; set; } 19 | public DateTime OccurredOnUtc { get; set; } 20 | public DateTime? ProceddedOnUtc { get; set; } 21 | public string? Error { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /MicroService/Catalog.Service/Catalogs.Domain/OutBoxMessage/OutBoxMessageConsumer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Catalogs.Domain.OutBoxMessage 10 | { 11 | [Table("OutboxMessageConsumer")] 12 | public class OutboxMessageConsumer 13 | { 14 | [Key] 15 | [DatabaseGenerated(DatabaseGeneratedOption.None)] // 指定非自增 16 | 17 | public long Id { get; set; } 18 | public string Name { get; set; } 19 | public string? Error { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /MicroService/Catalog.Service/Catalogs.Infrastructure/Catalogs.Infrastructure.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /MicroService/Catalog.Service/Catalogs.Infrastructure/Database/CatalogContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Catalogs.Domain.Catalogs; 7 | using Catalogs.Domain.OutBoxMessage; 8 | using Microsoft.EntityFrameworkCore; 9 | using Catalogs.Domain.OutBoxMessage; 10 | 11 | namespace Catalogs.Infrastructure.Database 12 | { 13 | public class CatalogContext:DbContext 14 | { 15 | public CatalogContext(DbContextOptions options):base(options) 16 | { 17 | 18 | } 19 | 20 | public DbSet Catalogs { get; set; } 21 | public DbSet OutBoxMessageConsumers { get; set; } 22 | public DbSet OutBoxMessages { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /MicroService/Catalog.Service/Catalogs.WebApi/Catalogs.WebApi.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Always 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /MicroService/Catalog.Service/Catalogs.WebApi/Controllers/CatalogController.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/MicroService/Catalog.Service/Catalogs.WebApi/Controllers/CatalogController.cs -------------------------------------------------------------------------------- /MicroService/Catalog.Service/Catalogs.WebApi/Program.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/MicroService/Catalog.Service/Catalogs.WebApi/Program.cs -------------------------------------------------------------------------------- /MicroService/Catalog.Service/Catalogs.WebApi/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:62585", 8 | "sslPort": 44374 9 | } 10 | }, 11 | "profiles": { 12 | "http": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "http://localhost:5138", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "https": { 23 | "commandName": "Project", 24 | "dotnetRunMessages": true, 25 | "launchBrowser": true, 26 | "launchUrl": "swagger", 27 | "applicationUrl": "https://localhost:7210;http://localhost:7000", 28 | "environmentVariables": { 29 | "ASPNETCORE_ENVIRONMENT": "Development" 30 | } 31 | }, 32 | "IIS Express": { 33 | "commandName": "IISExpress", 34 | "launchBrowser": true, 35 | "launchUrl": "swagger", 36 | "environmentVariables": { 37 | "ASPNETCORE_ENVIRONMENT": "Development" 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /MicroService/Catalog.Service/Catalogs.WebApi/ViewModel/PaginatedViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace Catalogs.WebApi.ViewModel 2 | { 3 | public class PaginatedViewModel where TEntity : class 4 | { 5 | public int PageIndex { get; private set; } 6 | 7 | public int PageSize { get; private set; } 8 | 9 | public long Count { get; private set; } 10 | 11 | public IEnumerable Data { get; private set; } 12 | 13 | public PaginatedViewModel(int pageIndex, int pageSize, long count, IEnumerable data) 14 | { 15 | PageIndex = pageIndex; 16 | PageSize = pageSize; 17 | Count = count; 18 | Data = data; 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /MicroService/Catalog.Service/Catalogs.WebApi/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /MicroService/Catalog.Service/Catalogs.WebApi/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "ConnectionString": "Data Source=localhost,1401;Initial Catalog=catalog.service;User ID=sa;Password=Xx123456Yy@!;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False", 10 | "DistributedRedis": { 11 | "ConnectionString": "localhost:6379" 12 | }, 13 | "Redis": { 14 | "Password": "123456", 15 | "AllowAdmin": true, 16 | "Ssl": false, 17 | "ConnectTimeout": 6000, 18 | "ConnectRetry": 2, 19 | "Database": 1, 20 | "Name": "Catalog.WebApi", 21 | "PoolSize": 20, 22 | "Hosts": [ 23 | { 24 | "Host": "localhost", 25 | "Port": "6379" 26 | } 27 | ] 28 | }, 29 | "MqSetting": { 30 | "Use": 2, //1 代表kafka,2 代表Rabbit 31 | "PublishLog": true, 32 | "ConsumerLog": true, 33 | "Kafka": { 34 | "BootstrapServers": "localhost:9092", 35 | "Key": "kafka", 36 | "SaslUserName": "", 37 | "SaslPassWord": "" 38 | }, 39 | "RabbitMq": { 40 | "ConnectionString": "amqp://localhost:5672", //多个用;隔开 41 | "UserName": "admin", 42 | "Password": "admin", 43 | "Port": 5672, 44 | "SslEnabled": false 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /MicroService/Catalog.Service/Catalogs.WebApi/wwwroot/Img/R.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/MicroService/Catalog.Service/Catalogs.WebApi/wwwroot/Img/R.jpg -------------------------------------------------------------------------------- /MicroService/Catalog.Service/Catalogs.WebApi/wwwroot/Img/dog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/MicroService/Catalog.Service/Catalogs.WebApi/wwwroot/Img/dog.png -------------------------------------------------------------------------------- /MicroService/Catalog.Service/Catalogs.WebApi/wwwroot/Img/phone.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/MicroService/Catalog.Service/Catalogs.WebApi/wwwroot/Img/phone.jpg -------------------------------------------------------------------------------- /MicroService/Customer.Service/Custoemr.domain/Customers.Domain.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /MicroService/Customer.Service/Custoemr.domain/Customers/Customer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using System.Linq; 6 | using System.Runtime.InteropServices; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace Customers.Domain.Customers 11 | { 12 | [Table("customer")] 13 | public class Customer 14 | { 15 | [Key] 16 | [DatabaseGenerated(DatabaseGeneratedOption.None)] // 指定非自增 17 | public long Id { get; set; } 18 | public string UserName { get; set; } 19 | public string PassWord { get; set; } 20 | public DateTime CreateTime { get; set; } 21 | public bool IsDeleted { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /MicroService/Customer.Service/Custoemr.domain/Customers/ICustomerRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Customers.Domain.Customers 9 | { 10 | public interface ICustomerRepository 11 | { 12 | Task Get(string name,string password); 13 | Task Add(Customer customer); 14 | Task GetById(long id); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /MicroService/Customer.Service/Custoemr.domain/Customers/MissingCustomer.cs: -------------------------------------------------------------------------------- 1 | namespace Customers.Domain.Customers; 2 | 3 | public class MissingCustomer:Customer 4 | { 5 | public static readonly MissingCustomer Instance = new MissingCustomer(); 6 | } 7 | -------------------------------------------------------------------------------- /MicroService/Customer.Service/Custoemr.domain/Seedwork/IUnitOfWork.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Customers.Domain.Seedwork 8 | { 9 | public interface IUnitOfWork 10 | { 11 | Task CommitAsync(CancellationToken cancellationToken = default); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /MicroService/Customer.Service/Customer.Infrastructure/Customers.Infrastructure.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /MicroService/Customer.Service/Customer.Infrastructure/Database/CustomerContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.EntityFrameworkCore; 7 | using Customers.Domain.Customers; 8 | 9 | namespace Customers.Infrastructure.Database 10 | { 11 | public class CustomerContext:DbContext 12 | { 13 | public CustomerContext(DbContextOptions options) : base(options) { } 14 | public DbSet Customers { get; set; } 15 | protected override void OnModelCreating(ModelBuilder modelBuilder) 16 | { 17 | modelBuilder.ApplyConfigurationsFromAssembly(typeof(CustomerContext).Assembly); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /MicroService/Customer.Service/Customer.Infrastructure/Domain/Customers/CustomerRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.Cryptography; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Common.Util; 8 | using Customers.Domain.Customers; 9 | using Customers.Infrastructure.Database; 10 | using Microsoft.EntityFrameworkCore; 11 | 12 | namespace Customers.Infrastructure.Domain.Customers 13 | { 14 | public class CustomerRepository : ICustomerRepository 15 | { 16 | private readonly CustomerContext _; 17 | public CustomerRepository(CustomerContext context) 18 | { 19 | _ = context??throw new ArgumentNullException(nameof(context)); 20 | } 21 | public async Task Add(Customer customer) 22 | { 23 | customer.PassWord = CryptionHelper.CalculateSHA3Hash(customer.PassWord); 24 | await _.AddAsync(customer); 25 | } 26 | 27 | public async Task Get(string name, string password) 28 | { 29 | password = CryptionHelper.CalculateSHA3Hash(password); 30 | return await _.Customers.FirstOrDefaultAsync(x=>x.UserName==name&&x.PassWord == password); 31 | } 32 | public async Task GetById(long id) 33 | { 34 | return await _.Customers.FirstOrDefaultAsync(x=>x.Id==id); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /MicroService/Customer.Service/Customer.Infrastructure/Domain/UnitOfWork.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Customers.Domain.Seedwork; 7 | using Customers.Infrastructure.Database; 8 | 9 | namespace Customers.Infrastructure.Domain 10 | { 11 | public class UnitOfWork : IUnitOfWork 12 | { 13 | private readonly CustomerContext _; 14 | public UnitOfWork(CustomerContext ordersContext) 15 | { 16 | _= ordersContext; 17 | } 18 | public async Task CommitAsync(CancellationToken cancellationToken = default) 19 | { 20 | return await _.SaveChangesAsync(cancellationToken); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /MicroService/Customer.Service/Customer.WebApi/Customers.Center.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | Always 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /MicroService/Customer.Service/Customer.WebApi/GrpcService/GrpcCustomerService.cs: -------------------------------------------------------------------------------- 1 | using System.Security.Claims; 2 | using System.Text; 3 | using Customers.Center.Service; 4 | using Customers.Domain.Customers; 5 | using GrpcService.CustomerService; 6 | using MagicOnion; 7 | using MagicOnion.Server; 8 | using Microsoft.IdentityModel.Tokens; 9 | 10 | namespace Customers.Center.GrpcService 11 | { 12 | public class GrpcCustomerService : ServiceBase, IGrpcCustomerService 13 | { 14 | private readonly ICustomerService _customerService; 15 | 16 | public GrpcCustomerService(ICustomerService customerService) 17 | { 18 | _customerService = customerService; 19 | } 20 | public async UnaryResult GetCustomer(CustomerRequest request) 21 | { 22 | var customer = await _customerService.GetCustomer(new Service.Dtos.LoginDto(request.username, request.password)); 23 | return new CustomerResponse(customer.UserName??""); 24 | } 25 | public async UnaryResult GetUseIdFromToken(String token) 26 | { 27 | var userId = await _customerService.GetUseIdFromToken(token); 28 | return new UserIdResponse(userId); 29 | } 30 | 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /MicroService/Customer.Service/Customer.WebApi/Program.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/MicroService/Customer.Service/Customer.WebApi/Program.cs -------------------------------------------------------------------------------- /MicroService/Customer.Service/Customer.WebApi/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:28598", 8 | "sslPort": 44354 9 | } 10 | }, 11 | "profiles": { 12 | "Customer.WebApi": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:7263;http://localhost:7005", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /MicroService/Customer.Service/Customer.WebApi/Service/Dtos/AddCustomerDto.cs: -------------------------------------------------------------------------------- 1 | namespace Customers.Center.Service.Dtos 2 | { 3 | public record AddCustomerDto(string user,string password) 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /MicroService/Customer.Service/Customer.WebApi/Service/Dtos/LoginDto.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace Customers.Center.Service.Dtos 4 | { 5 | 6 | public record LoginDto([Required]string username,[Required]string password); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /MicroService/Customer.Service/Customer.WebApi/Service/Dtos/TokenDto.cs: -------------------------------------------------------------------------------- 1 | namespace Customers.Center.Service.Dtos 2 | { 3 | /// 4 | /// 5 | /// 6 | /// token 7 | /// 是否成功 8 | /// 消息 9 | public record TokenDto 10 | { 11 | public bool IsSuccess { get; set; } 12 | public string Token { get; set; } 13 | public string Message { get; set; } 14 | public string RefreshToken { get; set; } // 添加 RefreshToken 15 | public TokenDto(bool isSuccess, string token, string message) 16 | { 17 | IsSuccess = isSuccess; 18 | Token = token; 19 | Message = message; 20 | } 21 | public TokenDto(string refreshToken):this(true, "", "") 22 | { 23 | RefreshToken = refreshToken; 24 | } 25 | } 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /MicroService/Customer.Service/Customer.WebApi/Service/ICustomerService.cs: -------------------------------------------------------------------------------- 1 | using Customers.Center.Service.Dtos; 2 | using Customers.Domain.Customers; 3 | using Microsoft.EntityFrameworkCore.SqlServer.Query.Internal; 4 | 5 | namespace Customers.Center.Service 6 | { 7 | public interface ICustomerService 8 | { 9 | Task GetCustomer(LoginDto loginDto); 10 | Task AddCustomer(AddCustomerDto customerDto); 11 | Task GetToken(LoginDto loginDto); 12 | Task GetUseIdFromToken(string token); 13 | Task RefreshToken(string refreshToken); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /MicroService/Customer.Service/Customer.WebApi/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /MicroService/Customer.Service/Customer.WebApi/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "jwt": { 10 | "secret": "BE4CC761-0A6D-4A24-B20E-845F24DEBB4A", 11 | "accessExpireHours": 24, 12 | "refreshExpireHours": 24 13 | }, 14 | "ConnectionString": "Data Source=localhost,1401;Initial Catalog=customer.service;User ID=sa;Password=Xx123456Yy@!;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False", 15 | "Kestrel": { 16 | "Endpoints": { 17 | "Http": { 18 | "Url": "https://localhost:5224" 19 | }, 20 | "gRPC": { 21 | "Url": "https://localhost:7021", 22 | "Protocols": "Http2" 23 | } 24 | } 25 | }, 26 | "DistributedRedis": { 27 | "ConnectionString": "localhost:6379,password=123456" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /MicroService/GrpcService/GrpcService/CustomerService/IGrpcCustomerService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using MagicOnion; 7 | using MessagePack; 8 | 9 | namespace GrpcService.CustomerService 10 | { 11 | public interface IGrpcCustomerService:IService 12 | { 13 | UnaryResult GetCustomer(CustomerRequest request); 14 | UnaryResult GetUseIdFromToken(string token); 15 | } 16 | 17 | [MessagePackObject(true)] 18 | public record CustomerRequest(string username, string password) 19 | { 20 | //public string UserName { get; set; } 21 | //public string Password { get; set; } 22 | 23 | //public CustomerRequest(string username, string password) 24 | //{ 25 | // UserName = username; 26 | // Password = password; 27 | //} 28 | } 29 | //public record CustomerRequest(string username, string password) 30 | //{ 31 | 32 | //} 33 | [MessagePackObject(true)] 34 | public record CustomerResponse(string username) 35 | { 36 | //public string UserName { get; set; } 37 | //public CustomerResponse(string username) 38 | //{ 39 | // UserName = username; 40 | //} 41 | } 42 | //public record CustomerResponse(string username) 43 | //{ 44 | 45 | //} 46 | [MessagePackObject(true)] 47 | public record UserIdResponse(long id); 48 | } 49 | -------------------------------------------------------------------------------- /MicroService/GrpcService/GrpcService/GrpcService.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /MicroService/GrpcService/GrpcService/OrderService/IGrpcOrderService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using GrpcService.CustomerService; 7 | using MagicOnion; 8 | using MessagePack; 9 | 10 | namespace GrpcService.OrderService 11 | { 12 | public interface IGrpcOrderService:IService 13 | { 14 | UnaryResult ChangeOrderStatus(ChangeOrderStatusRequest request); 15 | 16 | UnaryResult GetOrderStatus(GetOrderStatusRequest request); 17 | //待付款订单 18 | } 19 | 20 | [MessagePackObject(true)] 21 | public record ChangeOrderStatusResponse(bool success,string message); 22 | 23 | [MessagePackObject(true)] 24 | public record ChangeOrderStatusRequest(long orderId,int status); 25 | 26 | [MessagePackObject(true)] 27 | public record GetOrderStatusResponse(int status); 28 | 29 | [MessagePackObject(true)] 30 | public record GetOrderStatusRequest(long orderId); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /MicroService/Message.Service/Message.WebApi/Controllers/WeatherForecastController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace Message.WebApi.Controllers; 4 | 5 | [ApiController] 6 | [Route("[controller]")] 7 | public class WeatherForecastController : ControllerBase 8 | { 9 | private static readonly string[] Summaries = new[] 10 | { 11 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 12 | }; 13 | 14 | private readonly ILogger _logger; 15 | 16 | public WeatherForecastController(ILogger logger) 17 | { 18 | _logger = logger; 19 | } 20 | 21 | [HttpGet(Name = "GetWeatherForecast")] 22 | public IEnumerable Get() 23 | { 24 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 25 | { 26 | Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), 27 | TemperatureC = Random.Shared.Next(-20, 55), 28 | Summary = Summaries[Random.Shared.Next(Summaries.Length)] 29 | }) 30 | .ToArray(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /MicroService/Message.Service/Message.WebApi/Message.WebApi.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /MicroService/Message.Service/Message.WebApi/Program.cs: -------------------------------------------------------------------------------- 1 | var builder = WebApplication.CreateBuilder(args); 2 | 3 | // Add services to the container. 4 | 5 | builder.Services.AddControllers(); 6 | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle 7 | builder.Services.AddEndpointsApiExplorer(); 8 | builder.Services.AddSwaggerGen(); 9 | 10 | var app = builder.Build(); 11 | 12 | // Configure the HTTP request pipeline. 13 | if (app.Environment.IsDevelopment()) 14 | { 15 | app.UseSwagger(); 16 | app.UseSwaggerUI(); 17 | } 18 | 19 | app.UseHttpsRedirection(); 20 | 21 | app.UseAuthorization(); 22 | 23 | app.MapControllers(); 24 | 25 | app.Run(); 26 | -------------------------------------------------------------------------------- /MicroService/Message.Service/Message.WebApi/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:49897", 8 | "sslPort": 44396 9 | } 10 | }, 11 | "profiles": { 12 | "http": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "http://localhost:5198", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "https": { 23 | "commandName": "Project", 24 | "dotnetRunMessages": true, 25 | "launchBrowser": true, 26 | "launchUrl": "swagger", 27 | "applicationUrl": "https://localhost:7021;http://localhost:5198", 28 | "environmentVariables": { 29 | "ASPNETCORE_ENVIRONMENT": "Development" 30 | } 31 | }, 32 | "IIS Express": { 33 | "commandName": "IISExpress", 34 | "launchBrowser": true, 35 | "launchUrl": "swagger", 36 | "environmentVariables": { 37 | "ASPNETCORE_ENVIRONMENT": "Development" 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /MicroService/Message.Service/Message.WebApi/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | namespace Message.WebApi; 2 | 3 | public class WeatherForecast 4 | { 5 | public DateOnly Date { get; set; } 6 | 7 | public int TemperatureC { get; set; } 8 | 9 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 10 | 11 | public string? Summary { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /MicroService/Message.Service/Message.WebApi/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /MicroService/Message.Service/Message.WebApi/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.Domain/Dtos/CatalogCopy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Text.Json.Serialization; 8 | using System.Threading.Tasks; 9 | 10 | namespace Ordering.Domain.Dtos 11 | { 12 | [Serializable] 13 | public class CatalogCopy 14 | { 15 | public long Id { get; set; } 16 | public string Name { get; set; } 17 | public string Description { get; set; } 18 | public decimal Price { get; set; } 19 | public int Stock { get; set; } 20 | public int MaxStock { get; set; } = 10000; 21 | public string ImgPath { get; set; } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.Domain/Dtos/CreateOrderDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Ordering.Domain.Dtos 8 | { 9 | public record CreateOrderDto(long pid, int quantity, decimal price) 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.Domain/Dtos/OrderDetailDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.Serialization; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Ordering.Domain.Enums; 8 | using Orleans; 9 | using Orleans.CodeGeneration; 10 | 11 | namespace Ordering.Domain.Dtos 12 | { 13 | [GenerateSerializer] 14 | public record OrderDetailDto 15 | { 16 | [Id(0)] 17 | public string ProductName { get; set; } 18 | [Id(1)] 19 | public string Quantity { get; set; } 20 | [Id(2)] 21 | public string OrderStatus { get; set; } 22 | [Id(3)] 23 | public string TotalAmount { get; set; } 24 | [Id(4)] 25 | public string CreateTime { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.Domain/Enums/OrderStatus.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Ordering.Domain.Enums 9 | { 10 | public enum OrderStatus 11 | { 12 | [Description("待确认")] 13 | BeConfirm=1, 14 | [Description("待付款")] 15 | Pending=2, // 16 | [Description("付款完成")] 17 | Processing=3, // 18 | [Description("已发货")] 19 | Shipped=4, // 20 | [Description("已送达")] 21 | Delivered=5, // 22 | [Description("已完成")] 23 | Completed=6, // 24 | [Description("已取消")] 25 | Canceled=7, // 26 | [Description("失败")] 27 | Failed=8 // 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.Domain/Events/CreateOrderEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Ordering.Domain.Events 8 | { 9 | public class CreateOrderEvent:IDomainEvent 10 | { 11 | public long EventId { get;set; } 12 | public long UserId { get; private set; } 13 | public long ProductId { get; private set; } 14 | public int Quantity { get;private set; } 15 | public CreateOrderEvent(long EventId, long userId,long productId,int quantity) 16 | { 17 | this.EventId = EventId; 18 | UserId = userId; 19 | ProductId=productId; 20 | Quantity = quantity; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.Domain/Events/IDomainEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Ordering.Domain.Events 8 | { 9 | public interface IDomainEvent 10 | { 11 | public long EventId { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.Domain/Events/IEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Ordering.Domain.Events 8 | { 9 | public abstract class IEntity 10 | { 11 | private long id; 12 | public virtual long Id 13 | { 14 | get { return id; } 15 | protected set { id = value; } 16 | } 17 | 18 | private List _domainEvents; 19 | public IReadOnlyCollection DomainEvents => _domainEvents?.AsReadOnly(); 20 | 21 | public void AddDomainEvent(IDomainEvent eventItem) 22 | { 23 | _domainEvents = _domainEvents ?? new List(); 24 | _domainEvents.Add(eventItem); 25 | } 26 | public void RemoveDomainEvent(IDomainEvent eventItem) 27 | { 28 | _domainEvents?.Remove(eventItem); 29 | } 30 | public void ClearDomainEvents() 31 | { 32 | _domainEvents?.Clear(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.Domain/Ordering.Domain.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.Domain/OutBoxMessages/OutBoxMessage.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace Ordering.Dimain.OutBoxMessages 5 | { 6 | [Table("OutBoxMessage")] 7 | public class OutBoxMessage 8 | { 9 | [Key] 10 | [DatabaseGenerated(DatabaseGeneratedOption.None)] // 指定非自增 11 | public long Id { get; set; } 12 | public string Type { get; set; } 13 | public string Content { get; set; } 14 | public DateTime OccurredOnUtc { get; set; } 15 | public DateTime? ProceddedOnUtc { get; set; } 16 | public string? Error { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.IGrain/IOrderGrain.cs: -------------------------------------------------------------------------------- 1 | using Ordering.Domain.Dtos; 2 | using Orleans; 3 | 4 | namespace Ordering.IGrain 5 | { 6 | public interface IOrderGrain: IGrainWithIntegerKey 7 | { 8 | Task Create(CreateOrderDto orderDto); 9 | Task> GetOrderDetails(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.IGrain/Ordering.IGrain.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.Infrastructure/Ordering.Infrastructure.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.Infrastructure/Repositories/Orders/IReadOrderRepository.cs: -------------------------------------------------------------------------------- 1 |  2 | using RepositoryComponent.BaseRepo; 3 | using Ordering.Domain.Orders; 4 | 5 | namespace Ordering.Infrastructure.Repositories 6 | { 7 | public interface IReadOrderRepository : IReadRepository 8 | { 9 | ValueTask GetById(long id); 10 | } 11 | 12 | 13 | } 14 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.Infrastructure/Repositories/Orders/IWriteOrderRepository.cs: -------------------------------------------------------------------------------- 1 | using RepositoryComponent.BaseRepo; 2 | using Ordering.Domain.Orders; 3 | 4 | namespace Ordering.Infrastructure.Repositories 5 | { 6 | public interface IWriteOrderRepository : IWriteRepository 7 | { 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.Infrastructure/Repositories/Orders/OrderReadRepository.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.EntityFrameworkCore.Internal; 3 | using Ordering.Domain.Orders; 4 | using Ordering.Infrastructure.Database; 5 | using RepositoryComponent.BaseRepo; 6 | using RepositoryComponent.DbFactories; 7 | 8 | namespace Ordering.Infrastructure.Repositories 9 | { 10 | public class OrderReadRepository : ReadRepository, IReadOrderRepository 11 | { 12 | private readonly ReadOrderDbContext _readContext; 13 | 14 | 15 | public OrderReadRepository(DbFactory readContextFactory) : base(readContextFactory) 16 | { 17 | _readContext = readContextFactory?.Context; 18 | } 19 | 20 | public async ValueTask GetById(long id) 21 | { 22 | var result = await _readContext.Set().Where(x => x.Id == id).FirstOrDefaultAsync(); 23 | return result; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.Infrastructure/Repositories/Orders/OrderWriteRepository.cs: -------------------------------------------------------------------------------- 1 | using Ordering.Domain.Orders; 2 | using Ordering.Infrastructure.Database; 3 | using RepositoryComponent.BaseRepo; 4 | using RepositoryComponent.DbFactories; 5 | 6 | namespace Ordering.Infrastructure.Repositories 7 | { 8 | public class OrderWriteRepository : WriteRepository, IWriteOrderRepository 9 | { 10 | private readonly WriteOrderDbContext _readContext; 11 | 12 | 13 | public OrderWriteRepository(DbFactory readContextFactory) : base(readContextFactory) 14 | { 15 | _readContext = readContextFactory?.Context; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.Infrastructure/Repositories/OutBox/IReadOutBoxMessageRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Ordering.Dimain.OutBoxMessages; 7 | using Ordering.Domain.Orders; 8 | using RepositoryComponent.BaseRepo; 9 | 10 | namespace Ordering.Infrastructure.Repositories 11 | { 12 | public interface IReadOutBoxMessageRepository : IReadRepository 13 | { 14 | Task> GetTake(int count); 15 | ValueTask GetById(long id); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.Infrastructure/Repositories/OutBox/IWriteOutBoxMessageRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Ordering.Dimain.OutBoxMessages; 7 | using Ordering.Domain.Orders; 8 | using RepositoryComponent.BaseRepo; 9 | 10 | namespace Ordering.Infrastructure.Repositories 11 | { 12 | public interface IWriteOutBoxMessageRepository: IWriteRepository 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.Infrastructure/Repositories/OutBox/ReadOutBoxMessageRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.EntityFrameworkCore; 7 | using Ordering.Dimain.OutBoxMessages; 8 | using Ordering.Domain.Orders; 9 | using Ordering.Infrastructure.Database; 10 | using RepositoryComponent.BaseRepo; 11 | using RepositoryComponent.DbFactories; 12 | 13 | namespace Ordering.Infrastructure.Repositories 14 | { 15 | public class ReadOutBoxMessageRepository: ReadRepository, IReadOutBoxMessageRepository 16 | { 17 | private readonly ReadOrderDbContext _readContext; 18 | 19 | 20 | public ReadOutBoxMessageRepository(DbFactory readContextFactory) : base(readContextFactory) 21 | { 22 | _readContext = readContextFactory?.Context; 23 | } 24 | 25 | public async ValueTask GetById(long id) 26 | { 27 | var result = await _readContext.Set().Where(x => x.Id == id).FirstOrDefaultAsync(); 28 | return result; 29 | } 30 | 31 | public async Task> GetTake(int count) 32 | { 33 | var messages = await _readContext.Set().Where(m => m.ProceddedOnUtc == null) 34 | .Take(count).ToListAsync(); 35 | return messages; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.Infrastructure/Repositories/OutBox/WriteOutBoxMessageRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Ordering.Dimain.OutBoxMessages; 7 | using Ordering.Domain.Orders; 8 | using Ordering.Infrastructure.Database; 9 | using RepositoryComponent.BaseRepo; 10 | using RepositoryComponent.DbFactories; 11 | 12 | namespace Ordering.Infrastructure.Repositories 13 | { 14 | internal class WriteOutBoxMessageRepository : WriteRepository, IWriteOutBoxMessageRepository 15 | { 16 | private readonly WriteOrderDbContext _writeContext; 17 | 18 | 19 | public WriteOutBoxMessageRepository(DbFactory writeContextFactory) : base(writeContextFactory) 20 | { 21 | _writeContext = writeContextFactory?.Context; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.WebApi/Const.cs: -------------------------------------------------------------------------------- 1 | namespace Ordering.WebApi 2 | { 3 | 4 | public static class Const 5 | { 6 | public const string Normal_Queue = "paying_exchange.normal_queue"; 7 | public const string Normal_Exchange = "paying_exchange.normal"; 8 | public const string Normal_RoutingKey = "paying_exchange.normal_key"; 9 | public const string Delay_Queue = "paying_exchange.dl_queue"; 10 | public const string Delay_Exchange = "paying_exchange.dl"; 11 | public const string Delay_RoutingKey = "paying_exchange.dl_key"; 12 | public const long DelayTime = 1000*60*2; 13 | } 14 | public record RabbitMqConfig 15 | { 16 | public string Host { get; set; } = "127.0.0.1"; 17 | public int Port { get; set; } = 5672; 18 | public string UserName { get; set; } = "admin"; 19 | public string Password { get; set; } = "admin"; 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.WebApi/Controllers/OrderController.cs: -------------------------------------------------------------------------------- 1 | using Grpc.Net.Client; 2 | using GrpcService.CustomerService; 3 | using MagicOnion.Client; 4 | using Microsoft.AspNetCore.Authorization; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Ordering.Domain.Dtos; 7 | using Ordering.Domain.Orders; 8 | using Ordering.IGrain; 9 | using Ordering.WebApi.Filters; 10 | using Orleans; 11 | 12 | namespace Ordering.WebApi.Controllers; 13 | 14 | 15 | [AsyncAuthorizationFilter] 16 | [ApiController] 17 | [Route("[controller]")] 18 | public class OrderController : ControllerBase 19 | { 20 | private readonly ILogger _logger; 21 | private readonly IGrainFactory _clusterClient; 22 | 23 | public OrderController(ILogger logger, IGrainFactory clusterClient) 24 | { 25 | _logger = logger; 26 | _clusterClient = clusterClient; 27 | } 28 | 29 | [HttpPost] 30 | [Route("Create")] 31 | 32 | public async Task Create(CreateOrderDto orderDto) 33 | { 34 | if(orderDto.pid == 0 || orderDto.price==0||orderDto.quantity==0) 35 | { 36 | return false; 37 | } 38 | var orderGrain = _clusterClient.GetGrain(Random.Shared.Next()); 39 | 40 | return await orderGrain.Create(orderDto); 41 | } 42 | 43 | [HttpGet] 44 | [Route("GetOrders")] 45 | public async Task> GetOrdersByUser() 46 | { 47 | var orderGrain = _clusterClient.GetGrain(Random.Shared.Next()); 48 | return await orderGrain.GetOrderDetails(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.WebApi/Ordering.WebApi.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | Always 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.WebApi/Program.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/MicroService/Ordering.Service/Ordering.WebApi/Program.cs -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.WebApi/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:5477", 8 | "sslPort": 44322 9 | } 10 | }, 11 | "profiles": { 12 | "Ordering.WebApi": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:7158;http://localhost:7105", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.WebApi/Services/Orders/IOrderService.cs: -------------------------------------------------------------------------------- 1 | namespace Ordering.WebApi.Services.Orders 2 | { 3 | public interface IOrderService 4 | { 5 | Task ChangeOrderStaus(long id, int status); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.WebApi/Services/Orders/OrderService.cs: -------------------------------------------------------------------------------- 1 |  2 | using GrpcService.OrderService; 3 | using Ordering.Domain.Enums; 4 | using Ordering.Infrastructure.Repositories; 5 | 6 | namespace Ordering.WebApi.Services.Orders 7 | { 8 | public class OrderService : IOrderService 9 | { 10 | private readonly IWriteOrderRepository _writeRepository; 11 | private readonly IReadOrderRepository _readRepository; 12 | public OrderService(IWriteOrderRepository writeOrderRepository, IReadOrderRepository readOrderRepository) 13 | { 14 | _writeRepository = writeOrderRepository; 15 | _readRepository = readOrderRepository; 16 | } 17 | public async Task ChangeOrderStaus(long id, int status) 18 | { 19 | var order = await _readRepository.GetById(id); 20 | if (order == null) 21 | { 22 | return false; 23 | } 24 | order.SetOrderStaus((OrderStatus)status); 25 | await _writeRepository.UpdateAsync(order); 26 | var result = await _writeRepository.SaveChangeAsync(); 27 | return result == 1; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.WebApi/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /MicroService/Ordering.Service/Ordering.WebApi/sql/order.service.sql: -------------------------------------------------------------------------------- 1 | /* 2 | 找不到数据库级别的扩展属性,或所有现有扩展属性在其他窗口中处于打开状态 3 | */ CREATE TABLE MOrder ( 4 | Id BIGINT PRIMARY KEY, 5 | UserId BIGINT NOT NULL, 6 | ProductId BIGINT NOT NULL, 7 | Quantity INT NOT NULL, 8 | TotalAmount DECIMAL(18, 2) NOT NULL, 9 | OrderStatus INT NOT NULL, 10 | CreateTime BIGINT NOT NULL, 11 | -- 添加适当的外键约束,参考具体的数据库关系 12 | ); 13 | CREATE TABLE OutBoxMessage ( 14 | Id BIGINT PRIMARY KEY, 15 | Type VARCHAR(255), -- You may adjust the length based on your needs 16 | Content TEXT, -- TEXT is used for potentially large content, adjust if needed 17 | OccurredOnUtc DATETIME, 18 | ProceddedOnUtc DATETIME, 19 | Error VARCHAR(MAX) -- Adjust the length based on your needs, or use TEXT if it can be large 20 | ); -------------------------------------------------------------------------------- /MicroService/Paying.Service/Paying.Domain/Paying.Domain.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /MicroService/Paying.Service/Paying.Infrastructure/Paying.Infrastructure.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /MicroService/Paying.Service/Paying.WebApi/Const.cs: -------------------------------------------------------------------------------- 1 | namespace Paying.WebApi 2 | { 3 | 4 | public static class Const 5 | { 6 | public const string Normal_Queue = "paying_exchange.normal_queue"; 7 | public const string Normal_Exchange = "paying_exchange.normal"; 8 | public const string Normal_RoutingKey = "paying_exchange.normal_key"; 9 | public const string Delay_Queue = "paying_exchange.dl_queue"; 10 | public const string Delay_Exchange = "paying_exchange.dl"; 11 | public const string Delay_RoutingKey = "paying_exchange.dl_key"; 12 | public const long DelayTime = 1000*60*5; 13 | } 14 | public record RabbitMqConfig 15 | { 16 | public string Host { get; set; } = "127.0.0.1"; 17 | public int Port { get; set; } = 5672; 18 | public string UserName { get; set; } = "admin"; 19 | public string Password { get; set; } = "admin"; 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /MicroService/Paying.Service/Paying.WebApi/Controllers/PayController.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/MicroService/Paying.Service/Paying.WebApi/Controllers/PayController.cs -------------------------------------------------------------------------------- /MicroService/Paying.Service/Paying.WebApi/Database/Payment.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace Paying.WebApi.Database 5 | { 6 | [Table("Payment")] 7 | public class Payment 8 | { 9 | [Key] 10 | [DatabaseGenerated(DatabaseGeneratedOption.None)] // 指定非自增 11 | public long Id { get; set; } 12 | public long OrderId { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /MicroService/Paying.Service/Paying.WebApi/Database/PaymentContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | 3 | namespace Paying.WebApi.Database 4 | { 5 | public class PaymentContext:DbContext 6 | { 7 | public PaymentContext(DbContextOptions options) : base(options) 8 | { 9 | } 10 | 11 | public DbSet Payments { get; set; } 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /MicroService/Paying.Service/Paying.WebApi/Dtos/CreateOrderEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Paying.WebApi.Dtos 8 | { 9 | public class CreateOrderEvent 10 | { 11 | public long EventId { get;set; } 12 | public long UserId { get; private set; } 13 | public long ProductId { get; private set; } 14 | public int Quantity { get;private set; } 15 | public CreateOrderEvent(long EventId, long userId,long productId,int quantity) 16 | { 17 | this.EventId = EventId; 18 | UserId = userId; 19 | ProductId=productId; 20 | Quantity = quantity; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /MicroService/Paying.Service/Paying.WebApi/Paying.WebApi.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | Always 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /MicroService/Paying.Service/Paying.WebApi/Program.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/MicroService/Paying.Service/Paying.WebApi/Program.cs -------------------------------------------------------------------------------- /MicroService/Paying.Service/Paying.WebApi/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:11913", 8 | "sslPort": 44372 9 | } 10 | }, 11 | "profiles": { 12 | "http": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "http://localhost:5046", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "https": { 23 | "commandName": "Project", 24 | "dotnetRunMessages": true, 25 | "launchBrowser": true, 26 | "launchUrl": "swagger", 27 | "applicationUrl": "https://localhost:7092;http://localhost:5046", 28 | "environmentVariables": { 29 | "ASPNETCORE_ENVIRONMENT": "Development" 30 | } 31 | }, 32 | "IIS Express": { 33 | "commandName": "IISExpress", 34 | "launchBrowser": true, 35 | "launchUrl": "swagger", 36 | "environmentVariables": { 37 | "ASPNETCORE_ENVIRONMENT": "Development" 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /MicroService/Paying.Service/Paying.WebApi/Services/IPayingService.cs: -------------------------------------------------------------------------------- 1 | using Paying.WebApi.Database; 2 | 3 | namespace Paying.WebApi.Services 4 | { 5 | public interface IPayingService 6 | { 7 | Task ChangeOrderStatus(long orderId,int status); 8 | Task GetOrderStatus(long orderId); 9 | Task IsPay(long orderId); 10 | Task Add(long orderId); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /MicroService/Paying.Service/Paying.WebApi/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /MicroService/Paying.Service/Paying.WebApi/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "GrpcServices": { 10 | "Order": "https://localhost:7160" 11 | }, 12 | "ConnectionString": "Data Source=localhost,1401;Initial Catalog=payment.service;User ID=sa;Password=Xx123456Yy@!;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False" 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Test/GrpcHttpService/JwtAuthApp.Server/Authentication/JwtTokenService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Options; 2 | using Microsoft.IdentityModel.Tokens; 3 | using System.IdentityModel.Tokens.Jwt; 4 | using System.Security.Claims; 5 | 6 | namespace JwtAuthApp.Server.Authentication 7 | { 8 | public class JwtTokenService 9 | { 10 | private readonly SymmetricSecurityKey _securityKey; 11 | 12 | public JwtTokenService(IOptions jwtTokenServiceOptions) 13 | { 14 | _securityKey = new SymmetricSecurityKey(Convert.FromBase64String(jwtTokenServiceOptions.Value.Secret)); 15 | } 16 | 17 | public (string Token, DateTime Expires) CreateToken(long userId, string displayName) 18 | { 19 | var jwtTokenHandler = new JwtSecurityTokenHandler(); 20 | var expires = DateTime.UtcNow.AddSeconds(10); 21 | var token = jwtTokenHandler.CreateEncodedJwt(new SecurityTokenDescriptor() 22 | { 23 | SigningCredentials = new SigningCredentials(_securityKey, SecurityAlgorithms.HmacSha256), 24 | Subject = new ClaimsIdentity(new[] 25 | { 26 | new Claim(ClaimTypes.Name, displayName), 27 | new Claim(ClaimTypes.NameIdentifier, userId.ToString()), 28 | }), 29 | Expires = expires, 30 | }); 31 | 32 | return (token, expires); 33 | } 34 | } 35 | 36 | public class JwtTokenServiceOptions 37 | { 38 | public string Secret { get; set; } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Test/GrpcHttpService/JwtAuthApp.Server/Controllers/WeatherForecastController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace JwtAuthApp.Server.Controllers 4 | { 5 | [ApiController] 6 | [Route("[controller]")] 7 | public class WeatherForecastController : ControllerBase 8 | { 9 | private static readonly string[] Summaries = new[] 10 | { 11 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 12 | }; 13 | 14 | private readonly ILogger _logger; 15 | 16 | public WeatherForecastController(ILogger logger) 17 | { 18 | _logger = logger; 19 | } 20 | 21 | [HttpGet(Name = "GetWeatherForecast")] 22 | public IEnumerable Get() 23 | { 24 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 25 | { 26 | Date = DateTime.Now.AddDays(index), 27 | TemperatureC = Random.Shared.Next(-20, 55), 28 | Summary = Summaries[Random.Shared.Next(Summaries.Length)] 29 | }) 30 | .ToArray(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Test/GrpcHttpService/JwtAuthApp.Server/JwtAuthApp.Server.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Always 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Test/GrpcHttpService/JwtAuthApp.Server/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:24320", 8 | "sslPort": 44335 9 | } 10 | }, 11 | "profiles": { 12 | "JwtAuthApp.Server": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:7021;http://localhost:5150", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Test/GrpcHttpService/JwtAuthApp.Server/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | namespace JwtAuthApp.Server 2 | { 3 | public class WeatherForecast 4 | { 5 | public DateTime Date { get; set; } 6 | 7 | public int TemperatureC { get; set; } 8 | 9 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 10 | 11 | public string? Summary { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /Test/GrpcHttpService/JwtAuthApp.Server/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Test/GrpcHttpService/JwtAuthApp.Server/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "JwtAuthApp.Server": { 3 | "JwtTokenService": { 4 | /* 64 bytes (512 bits) secret key */ 5 | "Secret": "/Z8OkdguxFFbaxOIG1q+V9HeujzMKg1n9gcAYB+x4QvhF87XcD8sQA4VsdwqKVuCmVrXWxReh/6dmVXrjQoo9Q==" 6 | } 7 | }, 8 | "Logging": { 9 | "LogLevel": { 10 | "Default": "Trace", 11 | "System": "Information", 12 | "Microsoft": "Information" 13 | } 14 | }, 15 | "Kestrel": { 16 | "Endpoints": { 17 | "Http": { 18 | "Url": "https://localhost:5224" 19 | }, 20 | "gRPC": { 21 | "Url": "https://localhost:7021", 22 | "Protocols": "Http2" 23 | } 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Test/GrpcHttpService/Login.Client/Controllers/LoginController.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/Test/GrpcHttpService/Login.Client/Controllers/LoginController.cs -------------------------------------------------------------------------------- /Test/GrpcHttpService/Login.Client/GrpcClient/LoginClientFactory.cs: -------------------------------------------------------------------------------- 1 | using Grpc.Net.Client; 2 | using MagicOnion.Client; 3 | using MicroService.Shared; 4 | using MicroService.Shared.GrpcPool; 5 | 6 | namespace Login.Client.GrpcClient 7 | { 8 | public class LoginClientFactory : IGrpcClientFactory 9 | { 10 | public IAccountService Create(GrpcChannel channel) 11 | { 12 | return MagicOnionClient.Create(channel); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Test/GrpcHttpService/Login.Client/Login.Client.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Test/GrpcHttpService/Login.Client/Program.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/Test/GrpcHttpService/Login.Client/Program.cs -------------------------------------------------------------------------------- /Test/GrpcHttpService/Login.Client/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:22285", 8 | "sslPort": 44388 9 | } 10 | }, 11 | "profiles": { 12 | "Login.Client": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:7060;http://localhost:5119", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Test/GrpcHttpService/Login.Client/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Login.Client; 8 | 9 | public class WeatherForecast 10 | { 11 | public DateTime Date { get; set; } 12 | 13 | public int TemperatureC { get; set; } 14 | 15 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 16 | 17 | public string Summary { get; set; } 18 | } 19 | -------------------------------------------------------------------------------- /Test/GrpcHttpService/Login.Client/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Test/GrpcHttpService/Login.Client/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "Grpc": { 10 | "Service": { 11 | "JwtAuthApp.ServiceAddress": "https://localhost:7021" 12 | }, 13 | "maxConnections": 10, 14 | "handoverTimeout":10 // seconds 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Test/GrpcHttpService/Login.Client002/Controllers/LoginController.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/Test/GrpcHttpService/Login.Client002/Controllers/LoginController.cs -------------------------------------------------------------------------------- /Test/GrpcHttpService/Login.Client002/GrpcClient/LoginClientFactory.cs: -------------------------------------------------------------------------------- 1 | using Grpc.Net.Client; 2 | using MagicOnion.Client; 3 | using MicroService.Shared; 4 | using MicroService.Shared.GrpcPool; 5 | 6 | namespace Login.Client002.GrpcClient 7 | { 8 | public class LoginClientFactory : IGrpcClientFactory 9 | { 10 | public IAccountService Create(GrpcChannel channel) 11 | { 12 | return MagicOnionClient.Create(channel); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Test/GrpcHttpService/Login.Client002/Login.Client002.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | PreserveNewest 21 | true 22 | PreserveNewest 23 | 24 | 25 | PreserveNewest 26 | true 27 | PreserveNewest 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Test/GrpcHttpService/Login.Client002/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:6072", 8 | "sslPort": 44300 9 | } 10 | }, 11 | "profiles": { 12 | "Login.Client002": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:7088;http://localhost:5094", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Test/GrpcHttpService/Login.Client002/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Test/GrpcHttpService/Login.Client002/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "Grpc": { 10 | "Service": { 11 | "JwtAuthApp.ServiceAddress": "https://localhost:7021" 12 | }, 13 | "minConnections":5, 14 | "maxConnections": 10, 15 | "handoverTimeout":10 // seconds 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Test/GrpcHttpService/MicroService.Shared/GrpcPool/IGrpcClientFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Channels; 6 | using System.Threading.Tasks; 7 | using Grpc.Core; 8 | using Grpc.Net.Client; 9 | 10 | namespace MicroService.Shared.GrpcPool 11 | { 12 | public interface IGrpcClientFactory 13 | { 14 | Tclient Create(GrpcChannel channel); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Test/GrpcHttpService/MicroService.Shared/MicroService.Shared.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Test/UnitTest/GlobalUsings.cs: -------------------------------------------------------------------------------- 1 | global using Microsoft.VisualStudio.TestTools.UnitTesting; -------------------------------------------------------------------------------- /Test/UnitTest/UnitTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | false 9 | true 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Test/UnitTest/UnitTest1.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/Test/UnitTest/UnitTest1.cs -------------------------------------------------------------------------------- /WebClient/Program.cs: -------------------------------------------------------------------------------- 1 | namespace WebClient 2 | { 3 | public class Program 4 | { 5 | public static void Main(string[] args) 6 | { 7 | var builder = WebApplication.CreateBuilder(args); 8 | 9 | // Add services to the container. 10 | 11 | builder.Services.AddControllers(); 12 | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle 13 | builder.Services.AddEndpointsApiExplorer(); 14 | builder.Services.AddSwaggerGen(); 15 | 16 | var app = builder.Build(); 17 | 18 | // Configure the HTTP request pipeline. 19 | if (app.Environment.IsDevelopment()) 20 | { 21 | app.UseSwagger(); 22 | app.UseSwaggerUI(); 23 | } 24 | app.UseStaticFiles(); 25 | app.UseHttpsRedirection(); 26 | 27 | app.UseAuthorization(); 28 | 29 | 30 | app.MapControllers(); 31 | 32 | app.Run(); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /WebClient/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:16853", 8 | "sslPort": 44338 9 | } 10 | }, 11 | "profiles": { 12 | "WebClient": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "login.html", 17 | "applicationUrl": "http://localhost:5254", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /WebClient/WebClient.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | <_ContentIncludedByDefault Remove="wwwroot\Login.html" /> 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | Always 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /WebClient/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /WebClient/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | -------------------------------------------------------------------------------- /WebClient/wwwroot/img/Login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/WebClient/wwwroot/img/Login.png -------------------------------------------------------------------------------- /WebClient/wwwroot/index.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | WebSocket Example 8 | 9 | 10 |

当前时间:

11 |
12 | 13 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /WebSocket.Server/Extensions/WebSocketExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using WsServer.Handler; 4 | using WsServer.Manager; 5 | using WsServer.Middleware; 6 | 7 | namespace WsServer.Extensions 8 | { 9 | public static class WebSocketExtensions 10 | { 11 | public static IApplicationBuilder MapWebSocketManager(this IApplicationBuilder app, 12 | string path, WebSocketHandler handler) 13 | { 14 | return app.Map(path, (x) => x.UseMiddleware(handler)); 15 | } 16 | 17 | public static IServiceCollection AddWebSocketManager(this IServiceCollection services) 18 | { 19 | services.AddTransient(); 20 | return services; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /WebSocket.Server/Manager/WebSocketConnectionManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Linq; 4 | using System.Net.WebSockets; 5 | using System.Threading.Tasks; 6 | using System.Threading; 7 | 8 | namespace WsServer.Manager 9 | { 10 | public class WebSocketConnectionManager 11 | { 12 | private readonly ConcurrentDictionary _sockets = new ConcurrentDictionary(); 13 | public WebSocket GetSocketById(string id) 14 | { 15 | _sockets.TryGetValue(id, out var socket); 16 | return socket; 17 | } 18 | 19 | public ConcurrentDictionary GetAll() 20 | { 21 | return _sockets; 22 | } 23 | 24 | public string GetId(WebSocket socket) 25 | { 26 | return _sockets.FirstOrDefault(x => x.Value == socket).Key; 27 | } 28 | 29 | public void AddSocket(WebSocket socket) 30 | { 31 | var id = Guid.NewGuid().ToString(); 32 | _sockets.TryAdd(id, socket); 33 | } 34 | 35 | public async Task RemoveSocketAsync(string id) 36 | { 37 | _sockets.TryRemove(id, out var socket); 38 | await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Closed by the WebSocketManager", CancellationToken.None); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /WebSocket.Server/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Hosting; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.Hosting; 4 | using Microsoft.Extensions.Logging; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WsServer 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /WebSocket.Server/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:2004", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "WsServer": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "applicationUrl": "http://localhost:5000", 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /WebSocket.Server/Services/TimeHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Net.WebSockets; 2 | using System.Threading.Tasks; 3 | using System; 4 | using WsServer.Manager; 5 | using WsServer.Handler; 6 | 7 | namespace WsServer.Services 8 | { 9 | public class TimeHandler : WebSocketHandler 10 | { 11 | private System.Threading.Timer _timer; 12 | public TimeHandler(WebSocketConnectionManager webSocketConnectionManager) : base(webSocketConnectionManager) 13 | { 14 | _timer = new System.Threading.Timer(SendTime, null, TimeSpan.Zero, TimeSpan.FromSeconds(1)); 15 | } 16 | private void SendTime(object state) 17 | { 18 | // 获取当前时间并发送给所有连接的客户端 19 | var currentTime = DateTime.Now.ToString("HH:mm:ss"); 20 | SendMessageToAllAsync($"Current Time: {currentTime}").Wait(); 21 | } 22 | public override async Task ReceiveAsync(WebSocket socket, WebSocketReceiveResult result, byte[] buffer) 23 | { 24 | var message = System.Text.Encoding.UTF8.GetString(buffer, 0, result.Count); 25 | var response = $"Received at {DateTime.Now:HH:mm:ss}"; 26 | 27 | await SendMessageAsync(socket, response); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /WebSocket.Server/WebScoket.Server.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /WebSocket.Server/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /WebSocket.Server/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*", 10 | "Redis": { 11 | "Password": "123456", 12 | "AllowAdmin": true, 13 | "Ssl": false, 14 | "ConnectTimeout": 6000, 15 | "ConnectRetry": 2, 16 | "Database": 1, 17 | "Name": "WebSocket.Server", 18 | "PoolSize": 20, 19 | "Hosts": [ 20 | { 21 | "Host": "localhost", 22 | "Port": "6379" 23 | } 24 | ] 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /project/App_Data/dbo.Customer.sql: -------------------------------------------------------------------------------- 1 | USE [workdb] 2 | GO 3 | 4 | /****** 对象: Table [dbo].[Customer] 脚本日期: 2023/9/8 12:05:05 ******/ 5 | SET ANSI_NULLS ON 6 | GO 7 | 8 | SET QUOTED_IDENTIFIER ON 9 | GO 10 | 11 | CREATE TABLE [dbo].[Customer] ( 12 | [Id] INT IDENTITY (1, 1) NOT NULL, 13 | [FirstName] VARCHAR (10) NOT NULL, 14 | [LastName] VARCHAR (10) NOT NULL, 15 | [CreateTime] BIGINT NOT NULL 16 | ); 17 | 18 | 19 | -------------------------------------------------------------------------------- /project/App_Data/dbo.Product.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE [dbo].[Product] ( 2 | [Id] BIGINT NOT NULL, 3 | [Name] NVARCHAR (MAX) NOT NULL, 4 | [Price] DECIMAL (18, 2) NOT NULL, 5 | [CreateTime] BIGINT NOT NULL, 6 | [Version] ROWVERSION NOT NULL, 7 | CONSTRAINT [PK_Product] PRIMARY KEY CLUSTERED ([Id] ASC) 8 | ); 9 | 10 | -------------------------------------------------------------------------------- /project/Attributes/FormatResponseAttribute.cs: -------------------------------------------------------------------------------- 1 | using Common.Util.Primitives; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Microsoft.AspNetCore.Mvc.Filters; 4 | using NuGet.Protocol; 5 | using project.Filters; 6 | 7 | namespace project.Attributes 8 | { 9 | public class FormatResponseAttribute:BaseActionFilter 10 | { 11 | protected override Task OnActionExecuted(ActionExecutedContext context) 12 | { 13 | if (context.ContainsFilter()) 14 | return Task.CompletedTask; 15 | if (context.Result is EmptyResult) 16 | context.Result = Success(); 17 | else if(context.Result is ObjectResult res) 18 | { 19 | if (res.Value is AjaxResult) 20 | context.Result = JsonContent(res.Value.ToJson()); 21 | else 22 | context.Result = Success(res.Value); 23 | } 24 | return Task.CompletedTask; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /project/Attributes/NoFormatResponseAttribute.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc.Filters; 2 | 3 | namespace project.Attributes 4 | { 5 | public class NoFormatResponseAttribute : Attribute, IActionFilter 6 | { 7 | public void OnActionExecuted(ActionExecutedContext context) 8 | { 9 | 10 | } 11 | 12 | public void OnActionExecuting(ActionExecutingContext context) 13 | { 14 | 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /project/Controllers/CustomerController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | using Microsoft.AspNetCore.Mvc; 3 | using project.Dapper; 4 | using project.Dtos; 5 | using project.Models; 6 | using project.Services; 7 | using project.Utility.Helper; 8 | 9 | namespace project.Controllers 10 | { 11 | [Route("api/[controller]")] 12 | [ApiController] 13 | public class CustomerController : ControllerBase 14 | { 15 | private readonly ICustomerService _customerService; 16 | public CustomerController(ICustomerService customerService) 17 | { 18 | _customerService = customerService; 19 | } 20 | 21 | [HttpPost] 22 | [Route("AddCustomer")] 23 | public Task AddCustomer(CreateCustomerDto dto) 24 | { 25 | _customerService.Add(dto); 26 | return Task.CompletedTask; 27 | } 28 | [HttpGet] 29 | [Route("GetCustomerList")] 30 | 31 | public async Task> GetCustomerList() 32 | { 33 | var result =await _customerService.GetCustomers(); 34 | return result; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /project/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using project.Models; 7 | using project.Services; 8 | using project.Utility.BaseController; 9 | using project.Utility.Helper; 10 | 11 | 12 | // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 13 | 14 | namespace project.Controllers 15 | { 16 | public class HomeController : AbsEfWorkController 17 | { 18 | private readonly IProductService _productService; 19 | 20 | public HomeController(IProductService eFCoreService) 21 | { 22 | _productService = eFCoreService; 23 | } 24 | 25 | protected override Task CreateOrUpdate(Product product) 26 | { 27 | 28 | throw new NotImplementedException(); 29 | } 30 | 31 | protected override Task Delete(KeyType entity) 32 | { 33 | throw new NotImplementedException(); 34 | } 35 | 36 | protected override Task PageResult() 37 | { 38 | throw new NotImplementedException(); 39 | } 40 | 41 | protected async override Task Search(KeyType searchId) 42 | { 43 | var result = await CacheHelper.GetAsync("test"); 44 | return Ok(result); 45 | } 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /project/Dapper/CustomerDal.cs: -------------------------------------------------------------------------------- 1 | using DapperDal; 2 | using project.Models; 3 | using project.Models; 4 | 5 | namespace project.Dapper 6 | { 7 | public class CustomerDal : DalBase 8 | { 9 | public CustomerDal(string configuration) : base(configuration) 10 | { 11 | 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /project/Dtos/Customer/CreateCustomerDto.cs: -------------------------------------------------------------------------------- 1 | namespace project.Dtos 2 | { 3 | public record CreateCustomerDto(string firstName,string lastName); 4 | 5 | } 6 | -------------------------------------------------------------------------------- /project/Dtos/Product/CreateProductDto.cs: -------------------------------------------------------------------------------- 1 | using project.Utility.Helper; 2 | 3 | namespace project.Dtos 4 | { 5 | public record class CreateProductDto(string name,decimal price) 6 | { 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /project/Dtos/Product/PageProductDto.cs: -------------------------------------------------------------------------------- 1 | namespace project.Dtos 2 | { 3 | public record class PageProductDto 4 | { 5 | public string? Name { get; set; } 6 | public decimal? Price { get; set; } 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /project/Elasticsearchs/Product/Parameters/EsProductParameter.cs: -------------------------------------------------------------------------------- 1 | namespace project.Elasticsearchs.Product.Parameters 2 | { 3 | public class EsProductParameter 4 | { 5 | private const int maxPageSize = 100; 6 | public int PageNumber { get; set; } = 1; 7 | 8 | private int _pageSize = 10; 9 | public int PageSize 10 | { 11 | get => _pageSize; 12 | set => _pageSize = value > maxPageSize ? maxPageSize : value; 13 | } 14 | 15 | public string KeyWords { get; set; } 16 | public string Content_Prefix { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /project/Elasticsearchs/Product/Search/EsProductContext.cs: -------------------------------------------------------------------------------- 1 | using Common.Util.Es.Foundation; 2 | using Nest; 3 | using project.Elasticsearchs.Product.Parameters; 4 | using project.Models; 5 | using SearchProduct = project.Models.Product; 6 | 7 | namespace project.Elasticsearchs.Product.Search 8 | { 9 | public class EsProductContext:EsBase 10 | { 11 | public EsProductContext(EsConfig esConfig) : base(esConfig) 12 | { 13 | } 14 | 15 | public override string IndexName => "es_product"; 16 | 17 | public Task> Search(EsProductParameter parameter) 18 | { 19 | var client = _esConfig.GetClient(IndexName); 20 | var query = new List, QueryContainer>>(); 21 | if (!string.IsNullOrWhiteSpace(parameter.KeyWords)) 22 | { 23 | query.Add(p => p.Match(m => m.Field(f => f.Name))); 24 | } 25 | 26 | var search = new SearchDescriptor(); 27 | search = search.Query(p => p.Bool( 28 | b => b.Must(query))) 29 | .From((parameter.PageNumber - 1) * parameter.PageSize).Size(parameter.PageSize); 30 | 31 | var response = client.Search(search); 32 | 33 | return Task.FromResult(response.Documents.ToList()); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /project/Extensions/ElasticSearchExtensions.cs: -------------------------------------------------------------------------------- 1 | using Common.Util.Es.Foundation; 2 | using project.Elasticsearchs.Product.Search; 3 | 4 | namespace project.Extensions 5 | { 6 | public static partial class TheExtensions 7 | { 8 | public static void AddEsSearch(this WebApplicationBuilder builder) 9 | { 10 | var section = builder.Configuration.GetSection("EsConfig"); 11 | builder.Services.AddSingleton(new EsConfig(section.Get())); 12 | builder.Services.AddTransient(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /project/Extensions/RedisExtensions.cs: -------------------------------------------------------------------------------- 1 | using project.Utility.Helper; 2 | 3 | namespace project.Extensions 4 | { 5 | public static partial class TheExtensions 6 | { 7 | public static void AddRedis(this WebApplicationBuilder builder) 8 | { 9 | var message = string.Empty; 10 | Task.WaitAny(new Task[]{ 11 | Task.Run(() => { 12 | CacheHelper.Init(builder.Configuration); //redis链接不上会死机 13 | return Task.CompletedTask; 14 | }), Task.Run(async () => { 15 | await Task.Delay(1000*30); 16 | message =$"{nameof(CacheHelper)} 初始化失败,redis可能连接不上,请重试"; 17 | }) 18 | }); 19 | if (!string.IsNullOrEmpty(message)) throw new Exception(message); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /project/Extensions/WatchDogExtensions.cs: -------------------------------------------------------------------------------- 1 | using WatchDog; 2 | using WatchDog.src.Enums; 3 | 4 | namespace project.Extensions 5 | { 6 | public static partial class TheExtensions 7 | { 8 | public static void AddWatchDog(this WebApplicationBuilder builder) 9 | { 10 | builder.Services.AddWatchDogServices(opt => 11 | { 12 | opt.IsAutoClear = true; 13 | opt.ClearTimeSchedule = WatchDogAutoClearScheduleEnum.Monthly; 14 | 15 | //opt.IsAutoClear = false; 16 | //opt.SetExternalDbConnString = "Server=localhost;Database=testDb;User Id=root;Password=root;"; 17 | //opt.DbDriverOption = WatchDogDbDriverEnum.MSSQL; 18 | }); 19 | } 20 | 21 | public static void UseWatchDog(this WebApplication app,IConfiguration configuration) 22 | { 23 | //https://localhost:7281/watchdog 24 | app.UseWatchDog(opt => 25 | { 26 | opt.WatchPageUsername = configuration["WatchDog:UserName"]??throw new ArgumentNullException("watchdoguserisnull"); 27 | opt.WatchPagePassword = configuration["WatchDog:PassWord"] ?? throw new ArgumentNullException("watchdogpwdisnull"); 28 | }); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /project/Filters/FilterExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc.Filters; 2 | 3 | namespace project.Filters 4 | { 5 | public static class FilterExtensions 6 | { 7 | public static bool ContainsFilter(this FilterContext actionExecutingContext) 8 | { 9 | return actionExecutingContext.Filters.Any(x=>x.GetType() == typeof(T)); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /project/Filters/GlobalExceptionFilter.cs: -------------------------------------------------------------------------------- 1 | using Common.Util.Primitives; 2 | using Microsoft.AspNetCore.Mvc.Filters; 3 | 4 | namespace project.Filters 5 | { 6 | public class GlobalExceptionFilter : BaseActionFilter, IAsyncExceptionFilter 7 | { 8 | private readonly ILogger _logger; 9 | public GlobalExceptionFilter(ILogger logger) 10 | { 11 | _logger = logger; 12 | } 13 | public Task OnExceptionAsync(ExceptionContext context) 14 | { 15 | Exception ex = context.Exception; 16 | if(ex is ShowException showEx) 17 | { 18 | _logger.LogInformation(showEx.Message); 19 | } 20 | else 21 | { 22 | _logger.LogError(ex,""); 23 | context.Result = Error("系统繁忙"); 24 | } 25 | return Task.CompletedTask; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /project/Filters/ValidFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc.Filters; 2 | 3 | namespace project.Filters 4 | { 5 | public class ValidFilter:BaseActionFilter 6 | { 7 | protected override Task OnActionExecuting(ActionExecutingContext context) 8 | { 9 | if (!context.ModelState.IsValid) 10 | { 11 | var list = context.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage); 12 | context.Result = Error(string.Join(", ", list)); 13 | } 14 | return Task.CompletedTask; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /project/Models/Common/IEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace project.Models.Common 3 | { 4 | public interface IEntity 5 | { 6 | } 7 | } 8 | 9 | -------------------------------------------------------------------------------- /project/Models/Common/MethodType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace project.Models.Common 3 | { 4 | public enum MethodType 5 | { 6 | POST, 7 | PUT, 8 | DELETE, 9 | GET 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /project/Models/Customer.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace project.Models 4 | { 5 | public class Customer 6 | { 7 | [Key] 8 | public int Id { get; set; } 9 | public string FirstName { get; set; } 10 | public string LastName { get; set; } 11 | public long CreateTime { get; set; } //不支持Version 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /project/Models/CustomerProfile.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using project.Dtos; 3 | using project.Utility.Helper; 4 | 5 | namespace project.Models 6 | { 7 | public class CustomerProfile:Profile 8 | { 9 | public CustomerProfile() 10 | { 11 | CreateMap().ForMember(e => e.CreateTime, opt => opt.MapFrom(src => TimestampHelper.ToUnixTimeMilliseconds(DateTime.UtcNow))); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /project/Models/Product.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | using project.Models.Common; 4 | 5 | namespace project.Models 6 | { 7 | [Table("Product")] 8 | public class Product:IEntity 9 | { 10 | [Key] 11 | public long Id { get; set; } 12 | public string Name { get; set; } 13 | public decimal Price { get; set; } 14 | public long CreateTime { get; set; } 15 | [NotMapped] //mysql不支持 16 | public byte[] Version { get; set; } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /project/Models/ProductProfile.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using project.Dtos; 3 | using project.Utility.Helper; 4 | 5 | namespace project.Models 6 | { 7 | public class ProductProfile:Profile 8 | { 9 | public ProductProfile() 10 | { 11 | CreateMap() 12 | .ForMember(e => e.CreateTime, opt => opt.MapFrom(src => TimestampHelper.ToUnixTimeMilliseconds(DateTime.UtcNow))) 13 | ; 14 | 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /project/Options/SlipExpirationRateLimitOptions.cs: -------------------------------------------------------------------------------- 1 | namespace project.Options 2 | { 3 | public class SlipExpirationRateLimitOptions 4 | { 5 | public const string SlipExpirationRateLimit = "SlipExpirationRateLimit"; 6 | public int PermitLimit { get; set; } = 100; 7 | public int Window { get; set; } = 10; 8 | public int ReplenishmentPeriod { get; set; } = 2; 9 | public int QueueLimit { get; set; } = 2; 10 | public int SegmentsPerWindow { get; set; } = 8; 11 | public int TokenLimit { get; set; } = 10; 12 | public int TokenLimit2 { get; set; } = 20; 13 | public int TokensPerPeriod { get; set; } = 4; 14 | public bool AutoReplenishment { get; set; } = false; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /project/Repositories/IReadProductRepository.cs: -------------------------------------------------------------------------------- 1 | using project.Models; 2 | using RepositoryComponent.BaseRepo; 3 | 4 | namespace project.Repositories 5 | { 6 | public interface IReadProductRepository:IReadRepository 7 | { 8 | ValueTask GetById(long id); 9 | } 10 | 11 | 12 | } 13 | -------------------------------------------------------------------------------- /project/Repositories/IWriteProductRepository.cs: -------------------------------------------------------------------------------- 1 | using project.Models; 2 | using RepositoryComponent.BaseRepo; 3 | 4 | namespace project.Repositories 5 | { 6 | public interface IWriteProductRepository:IWriteRepository 7 | { 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /project/Repositories/ProductReadRepository.cs: -------------------------------------------------------------------------------- 1 | using project.Context; 2 | using project.Models; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.Internal; 5 | using RepositoryComponent.BaseRepo; 6 | using RepositoryComponent.DbFactories; 7 | 8 | namespace project.Repositories 9 | { 10 | public class ProductReadRepository : ReadRepository, IReadProductRepository 11 | { 12 | private readonly ReadProductDbContext _readContext; 13 | 14 | 15 | public ProductReadRepository(DbFactory readContextFactory) : base(readContextFactory) 16 | { 17 | _readContext = readContextFactory?.Context; 18 | } 19 | 20 | public async ValueTask GetById(long id) 21 | { 22 | var result =await _readContext.Set().Where(x => x.Id == id).FirstOrDefaultAsync(); 23 | return result; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /project/Repositories/ProductWriteRepository.cs: -------------------------------------------------------------------------------- 1 | using project.Context; 2 | using project.Models; 3 | using project.Repositories; 4 | using project.Repositories; 5 | using RepositoryComponent.BaseRepo; 6 | using RepositoryComponent.DbFactories; 7 | 8 | namespace project.Repositories 9 | { 10 | public class ProductWriteRepository : WriteRepository, IWriteProductRepository 11 | { 12 | private readonly WriteProductDbContext _readContext; 13 | 14 | 15 | public ProductWriteRepository(DbFactory readContextFactory) : base(readContextFactory) 16 | { 17 | _readContext = readContextFactory?.Context; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /project/SeedWork/DatabaseStartup.cs: -------------------------------------------------------------------------------- 1 | using project.Context; 2 | using Microsoft.EntityFrameworkCore.Infrastructure; 3 | using Microsoft.EntityFrameworkCore.Storage; 4 | 5 | namespace project.SeedWork 6 | { 7 | public static class DatabaseStartup 8 | { 9 | public static void CreateTable(IServiceProvider service) 10 | { 11 | using var scope = service.CreateScope(); 12 | var context = scope.ServiceProvider.GetService(); 13 | if (context.Database.ProviderName.Equals("Microsoft.EntityFrameworkCore.InMemory")) 14 | { 15 | return; 16 | } 17 | if (!(context.GetService() as RelationalDatabaseCreator).Exists()) //数据库不存在自动创建,并建表 18 | { 19 | context.Database.EnsureDeleted(); 20 | context.Database.EnsureCreated(); 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /project/Services/Customer/CustomerService.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using project.Dapper; 3 | using project.Dtos; 4 | using project.Models; 5 | using project.Utility.Helper; 6 | using System.Configuration; 7 | 8 | namespace project.Services 9 | { 10 | public class CustomerService : ICustomerService 11 | { 12 | private readonly string _connectionString; 13 | private readonly IMapper _mapper; 14 | public CustomerService(IConfiguration configuration,IMapper mapper) 15 | { 16 | _connectionString = configuration["ConnectionStrings:SqlServer:WriteConnection"]; 17 | _mapper = mapper; 18 | } 19 | public async Task Add(CreateCustomerDto cdto) 20 | { 21 | await new CustomerDal(_connectionString).Insert( 22 | _mapper.Map(cdto)); 23 | } 24 | 25 | public async Task> GetCustomers() 26 | { 27 | var result =await new CustomerDal(_connectionString).GetList(); 28 | return result; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /project/Services/Customer/ICustomerService.cs: -------------------------------------------------------------------------------- 1 | using project.Dtos; 2 | using project.Models; 3 | 4 | namespace project.Services 5 | { 6 | public interface ICustomerService 7 | { 8 | Task> GetCustomers(); 9 | Task Add(CreateCustomerDto cdto); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /project/Services/IProductService.cs: -------------------------------------------------------------------------------- 1 | using project.Models; 2 | using project.Dtos; 3 | using RepositoryComponent.Page; 4 | 5 | namespace project.Services 6 | { 7 | public interface IProductService 8 | { 9 | Task Add(CreateProductDto product); 10 | Task> GetList(); 11 | ValueTask GetById(long id); 12 | Task Update(Product entity); 13 | Task Delete(Product entity); 14 | Task> PageList(PaginatedOptions query); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /project/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /project/obj/Debug/net7.0/.NETCoreApp,Version=v7.0.AssemblyAttributes.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using System.Reflection; 4 | [assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v7.0", FrameworkDisplayName = ".NET 7.0")] 5 | -------------------------------------------------------------------------------- /project/obj/Debug/net7.0/project.GlobalUsings.g.cs: -------------------------------------------------------------------------------- 1 | // 2 | global using global::Microsoft.AspNetCore.Builder; 3 | global using global::Microsoft.AspNetCore.Hosting; 4 | global using global::Microsoft.AspNetCore.Http; 5 | global using global::Microsoft.AspNetCore.Routing; 6 | global using global::Microsoft.Extensions.Configuration; 7 | global using global::Microsoft.Extensions.DependencyInjection; 8 | global using global::Microsoft.Extensions.Hosting; 9 | global using global::Microsoft.Extensions.Logging; 10 | global using global::System; 11 | global using global::System.Collections.Generic; 12 | global using global::System.IO; 13 | global using global::System.Linq; 14 | global using global::System.Net.Http; 15 | global using global::System.Net.Http.Json; 16 | global using global::System.Threading; 17 | global using global::System.Threading.Tasks; 18 | -------------------------------------------------------------------------------- /project/obj/Debug/net7.0/project.assets.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/project/obj/Debug/net7.0/project.assets.cache -------------------------------------------------------------------------------- /project/watchlogs-log.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/project/watchlogs-log.db -------------------------------------------------------------------------------- /project/watchlogs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/project/watchlogs.db -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | 电商业务,克隆下来可以正常运行,目前用的.NET6 2 | 包含redis缓存, 3 | 消息中间件kafka、rabbitmq, 4 | 数据库使用mysql、sqlserver 5 | 可以单独使用使用dapper 6 | ElasticSearch 7 | 微服务之间调用grpc,http,orleans,示例代码JwtAuthApp.Server、Login.Client 8 | 重点: 9 | 调用外部第三方服务可以用http请求,restshar库, 10 | 服务之间的调用用grpc,核心服务order通过orleans控制并发。 11 | orleans分布式高并发负载等特点,用作核心服务,比如订单处理,交易中心。 12 | 推送websocket 13 | Common.Util组件是工具类,有es和其他的组件使用,后期可以把redishelper和其他的helper都移进来。 14 | ConsumerClient 是简单的消息中间件的消费客户端示例 15 | project是webapi,示例项目。 16 | 关于使用es和sqlserver做数据实时同步,为了es查询的文档参考以前写的 17 | https://www.cnblogs.com/morec/p/17054383.html 18 | 或者自己查询其他的文档,mysql或者其他存储介质,其他数据之间同步蛮多的。 19 | 20 | 温馨提示:前端展示仅仅只是配合后端操作,没有花费任何时间做UI 21 | 温馨提示:有些非重点展示业务没有添加全部功能,比如注册,只是通过swagger接口创建用户而已 22 | 目录结构: 23 | ![Alt text](readmeimg/image-7.png) 24 | 25 | 登录: 26 | ![Alt text](readmeimg/image.png) 27 | 28 | 提前注册账号:admin 123456 29 | ![Alt text](readmeimg/image-1.png) 30 | 31 | 商品列表: 32 | 第一次加载请求接口,后续每秒钟websocket实时推送最新数据 33 | 34 | ![Alt text](readmeimg/image-6.png) 35 | 36 | 37 | 进入详情,下单后: 38 | ![Alt text](readmeimg/image-3.png) 39 | 40 | 购买列表 41 | 通过发件箱模式发送一条扣减库存的rabbitmq消息和一条延时队列,待确认改成待付款。 42 | 付款服务付款,延时队列消费掉上面的消息,判断该订单有没付款,已付款跳过,对于待付款的就取消,同时库存还原。 43 | 44 | ![Alt text](readmeimg/Snipaste_2024-01-12_13-22-07.png) 45 | 46 | ![Alt text](readmeimg/Snipaste_2024-01-12_13-22-35.png) 47 | 48 | ![Alt text](readmeimg/image-5.png) 49 | 50 | rabbitmq的队列: 51 | ![Alt text](readmeimg/Snipaste_2024-01-12_13-27-45.png) 52 | 53 | 后续: 54 | 55 | 发货... 56 | 完善:es商品查询 -------------------------------------------------------------------------------- /readmeimg/Snipaste_2024-01-12_13-22-07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/readmeimg/Snipaste_2024-01-12_13-22-07.png -------------------------------------------------------------------------------- /readmeimg/Snipaste_2024-01-12_13-22-35.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/readmeimg/Snipaste_2024-01-12_13-22-35.png -------------------------------------------------------------------------------- /readmeimg/Snipaste_2024-01-12_13-27-45.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/readmeimg/Snipaste_2024-01-12_13-27-45.png -------------------------------------------------------------------------------- /readmeimg/image-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/readmeimg/image-1.png -------------------------------------------------------------------------------- /readmeimg/image-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/readmeimg/image-2.png -------------------------------------------------------------------------------- /readmeimg/image-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/readmeimg/image-3.png -------------------------------------------------------------------------------- /readmeimg/image-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/readmeimg/image-4.png -------------------------------------------------------------------------------- /readmeimg/image-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/readmeimg/image-5.png -------------------------------------------------------------------------------- /readmeimg/image-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/readmeimg/image-6.png -------------------------------------------------------------------------------- /readmeimg/image-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/readmeimg/image-7.png -------------------------------------------------------------------------------- /readmeimg/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuzhixin405/netcore-micro/4a4e3b5d2aa4fe325cf8daf6615642463e5872d1/readmeimg/image.png -------------------------------------------------------------------------------- /用到的docker.txt: -------------------------------------------------------------------------------- 1 | sqlserver: 2 | docker run --name=sqlserver -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=Xx123456Yy@!" --memory 2000M -p 1401:1433 -d mcr.microsoft.com/mssql/server 3 | 4 | 5 | redis: 6 | docker run --name redis -p 6379:6379 -d --restart=always redis redis-server --appendonly yes --requirepass "123456" 7 | 8 | 9 | rabbitmq: 10 | docker run -d -p 15672:15672 -p 5672:5672 -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin --name rabbitmq rabbitmq:management --------------------------------------------------------------------------------