functional-programming-in-csharp-banking-sample

所属分类:Windows编程
开发工具:F#
文件大小:0KB
下载次数:0
上传日期:2023-07-31 06:41:59
上 传 者sh-1993
说明:  dotnet中的银行POC,包含函数编程元素,
(Banking POC in dotnet incorporating elements of functional programming,)

文件列表:
.config/ (0, 2023-12-13)
.config/dotnet-tools.json (350, 2023-12-13)
.editorconfig (230, 2023-12-13)
Account.App/ (0, 2023-12-13)
Account.App/Account.App.fsproj (1372, 2023-12-13)
Account.App/AccountActor.fs (10447, 2023-12-13)
Account.App/AccountApi.fs (923, 2023-12-13)
Account.App/AccountClosureActor.fs (4565, 2023-12-13)
Account.App/AccountClosureApi.fs (785, 2023-12-13)
Account.App/AccountSeederActor.fs (5749, 2023-12-13)
Account.App/SignalRProxy.fs (1207, 2023-12-13)
Account.Domain/ (0, 2023-12-13)
Account.Domain/Account.Domain.fsproj (625, 2023-12-13)
Account.Domain/Account.fs (12480, 2023-12-13)
Account.Domain/Commands.fs (5735, 2023-12-13)
Account.Domain/Events.fs (719, 2023-12-13)
Account.Domain/Types.fs (6721, 2023-12-13)
Account.Service/ (0, 2023-12-13)
Account.Service/Account.Service.fsproj (963, 2023-12-13)
Account.Service/Dockerfile (291, 2023-12-13)
Account.Service/Program.fs (6600, 2023-12-13)
Account.Service/Properties/ (0, 2023-12-13)
Account.Service/Properties/launchSettings.json (259, 2023-12-13)
Account.Service/appsettings.Development.json (749, 2023-12-13)
Archive/ (0, 2023-12-13)
Archive/CSharpWithLanguageExt/ (0, 2023-12-13)
Archive/CSharpWithLanguageExt/Account/ (0, 2023-12-13)
Archive/CSharpWithLanguageExt/Account/AccountActor.cs (3314, 2023-12-13)
Archive/CSharpWithLanguageExt/Account/Api.cs (3551, 2023-12-13)
Archive/CSharpWithLanguageExt/Account/Domain/ (0, 2023-12-13)
Archive/CSharpWithLanguageExt/Account/Domain/Account.cs (8825, 2023-12-13)
Archive/CSharpWithLanguageExt/Account/Domain/Commands.cs (1856, 2023-12-13)
Archive/CSharpWithLanguageExt/Account/Domain/Errors.cs (1047, 2023-12-13)
Archive/CSharpWithLanguageExt/Account/Domain/Events.cs (1430, 2023-12-13)
Archive/CSharpWithLanguageExt/Account/Domain/Validators.cs (942, 2023-12-13)
Archive/CSharpWithLanguageExt/Account/Hub.cs (591, 2023-12-13)
Archive/CSharpWithLanguageExt/Account/Routes.cs (4003, 2023-12-13)
Archive/CSharpWithLanguageExt/App.csproj (684, 2023-12-13)
Archive/CSharpWithLanguageExt/Config.cs (3246, 2023-12-13)
... ...

# Banking with Akka.NET ## Intro This project utilizes the actor model and event sourcing via Akka.NET to build typical banking functionality. Event sourcing is implemented with [Akka.Persistence](https://getakka.net/articles/persistence/architecture.html) via PostgreSQL. [Akka.Cluster.Sharding](https://getakka.net/articles/clustering/cluster-sharding.html) is used for the account aggregate root. Future/recurring actor message scheduling with PostgreSQL persistence is established via [Quartz.NET](https://www.quartz-scheduler.net/). ## Use Cases 1. Deposit 2. Debit 3. Registering a transfer recipient internal to the bank 4. Registering a transfer recipient in a 3rd party bank for domestic transfers 5. Transferring money to a registered recipient (internal to the bank) debits the sender and credits the receiver 6. Transferring money to an account in a mock 3rd party bank demonstrates resilience in face of intermittent network issues. Integration with Akka circuit breaker allows pending transfers to be reprocessed once the 3rd party bank is in a healthy state. 7. Recurring maintenance fee each billing cycle unless a qualified deposit found or a daily account balance threshold met. 8. Daily debit limit set by the customer 9. Lock/unlock debit card 10. Billing statements issued for each billing cycle 11. Emails sent for account open/close, billing statement, debit declined, & transfer deposited ![bank-dec-6-small](https://github.com/danne931/akka-dotnet-bank/assets/4181901/3e3a3bf1-5e37-424a-9898-fd8b513ac1af) ## UI I created a [simple](https://github.com/danne931/akka-dotnet-bank/blob/main/Web/wwwroot/js/account.js) web page to test the use cases against an account. [SignalR](https://dotnet.microsoft.com/en-us/apps/aspnet/signalr) is used to provide real-time feedback from actors to the UI: - Overall account state - History of transactions on the account - Toggling between a transfer sender & receiver account (internal to the bank) demonstrates debits in one account and credits in the other - A system operations navbar displays circuit breaker open/closed status for domestic transfers to the 3rd party bank mock server - When the circuit breaker closes, pending domestic transfers are reprocessed & corresponding Approved/Rejected events are interpolated into the table ## Demonstration ### Domestic transfers to a mock 3rd party bank server with circuit breaker integration: ![bank-domestic-transfer](https://github.com/danne931/akka-dotnet-bank/assets/4181901/0c504ddd-8b56-4bcb-9001-107f4833e3d1) ### Transfers to accounts internal to the bank: ![bank-internal-transfer](https://github.com/danne931/akka-dotnet-bank/assets/4181901/fd71e49f-f08b-4af1-9a64-3bac96490d98) ## Running with Kubernetes via minikube 1. Dependencies: .NET 7, [minikube](https://minikube.sigs.k8s.io/docs/start/), [helm](https://helm.sh/) 2. `sh build.sh -t RunK8sApp` 3. Browser opens automatically after all K8s resources start up 4. Enable postgres port forwarding if you want to inspect postgres in a local client: `sh postgres-port-forward-k8s.sh` (Server=postgres;Database=akkabank;Uid=testuser;Pwd=testpass) 5. View Akka cluster and actor info via [Petabridge.Cmd](https://cmd.petabridge.com/articles/commands/cluster-commands.html): ``` > minikube kubectl -- exec --stdin --tty account-cluster-0 -- /bin/bash > dotnet tool run pbm > cluster show > actor hierarchy ``` ## Running with Docker 1. Dependencies: .NET 7 2. `sh build.sh -t RunDockerApp` 3. Navigate to localhost:3000 4. If you want to inspect postgres in a dashboard you can visit localhost:5008 (Server=postgres;Database=akkabank;Uid=postgres;Pwd=password) ## Running without Docker or K8s 1. Dependencies: .NET 7, PostgreSQL & the psql command-line interface 2. Create a database (Server=localhost;Database=akkabank;Uid=postgres;Pwd=password) 3. Seed the database: `psql postgres < Infrastructure/Migrations/*.sql` 4. `cd` into ./Web, ./Account.Service, ./Scheduler.Service, & ./MockThirdPartyBankTransferReceiver & `dotnet run` in each ## Running tests 1. sh build.sh -t Test ## Archive Inspiration for this project stemmed from reading [Functional Programming in C#](https://www.manning.com/books/functional-programming-in-c-sharp-second-edition) by **Enrico Buonanno**. The first iteration of this project [(see CSharpWithLanguageExt directory)](https://github.com/danne931/akka-dotnet-bank/tree/main/Archive/CSharpWithLanguageExt) expands on **Enrico Buonanno**'s banking account example [actor](https://github.com/la-yumba/functional-csharp-code-2/blob/master/Examples/Chapter19/Boc/AccountProcess.cs) and [domain logic](https://github.com/la-yumba/functional-csharp-code-2/blob/master/Examples/Chapter13/Domain/Account.cs) to include additional business use cases as well as integration with more tech such as [EventStoreDB](https://www.eventstore.com/eventstoredb) and the de facto library for functional programming in C#, [language-ext](https://github.com/louthy/language-ext). The second iteration of this project [(see FSharpWithAkka directory)](https://github.com/danne931/akka-dotnet-bank/tree/main/Archive/FSharpWithAkka) is close to a one-to-one representation of the CSharpWithLanguageExt directory, with all use cases rewritten in F# and **Paul Louth**'s echo-process actor library replaced with Akka. I saw that [F#'s type inference](https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/type-inference) and [computation expressions](https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/computation-expressions) made writing programs with typed functional programming more second nature than with C# so I decided to continue with it for the third iteration.

近期下载者

相关文件


收藏者