{"id":18893593,"url":"https://github.com/seclerp/dependx","last_synced_at":"2025-10-30T00:21:13.176Z","repository":{"id":116434629,"uuid":"232463174","full_name":"seclerp/DependX","owner":"seclerp","description":"Library that provides F# DSL for dependency injection registration for your favorite IoC provider","archived":false,"fork":false,"pushed_at":"2020-01-22T16:20:28.000Z","size":42,"stargazers_count":4,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-24T05:37:29.483Z","etag":null,"topics":["autofac","dependency-injection","fsharp","ioc"],"latest_commit_sha":null,"homepage":"","language":"F#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/seclerp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-01-08T02:47:52.000Z","updated_at":"2025-02-14T14:30:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"6ec6a85f-6753-4148-a41d-acad1e24204c","html_url":"https://github.com/seclerp/DependX","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/seclerp/DependX","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seclerp%2FDependX","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seclerp%2FDependX/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seclerp%2FDependX/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seclerp%2FDependX/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seclerp","download_url":"https://codeload.github.com/seclerp/DependX/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seclerp%2FDependX/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270626798,"owners_count":24618684,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-15T02:00:12.559Z","response_time":110,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autofac","dependency-injection","fsharp","ioc"],"created_at":"2024-11-08T08:14:31.148Z","updated_at":"2025-10-30T00:21:13.077Z","avatar_url":"https://github.com/seclerp.png","language":"F#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch2 align=\"center\"\u003eDependX\u003c/h2\u003e\n\n\u003cp align=\"center\"\u003e \u003ca href=\"https://ci.appveyor.com/project/AndrewRublyov/dependx\"\u003e \u003cimg src=\"https://ci.appveyor.com/api/projects/status/7ep04nheqfav80on?svg=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003eLibrary that provides F# DSL for dependency injection registration for your favorite IoC provider\u003c/p\u003e\n\n---\n\n:warning: **Project in active development now and currently only supports Autofac container.**\n\nDependX allows you to change this:\n\n```fsharp\nlet deps =\n    let containerBuilder = ContainerBuilder()\n    \n    containerBuilder.RegisterType\u003cService\u003e()\n        .AsSelf()\n        .SingleInstance()\n        .Named(\"Some name\")\n        .WithParameter(\"abc\", 123)\n        .WithParameter(\"abc2\", fun _ -\u003e 123) |\u003e ignore\n    \n    containerBuilder.RegisterType\u003cService\u003e()\n        .As\u003cIService\u003e() |\u003e ignore\n\n    containerBuilder\n```\n\nInto this:\n```fsharp\nlet deps () = dependencies [\n    configure selfContract\u003cService\u003e {\n        lifetime singleton\n        named \"Some name\"\n        param \"abc\" (fromInstance 123)\n        param \"abc2\" (fromFactory \u003c| fun () -\u003e 123)\n    }\n    contract\u003cIService, Service\u003e\n]\n```\n\nAlso there are some helper functions to nicely get started into your .NET Core or ASP.NET Core environment\n\nCore library built on top of **.NET Startard 2.0**\n\nASP.NET Core extensions made for **ASP.NET Core 2.2+**\n\nAutofac libraries currently built on top of **Autofac 4.9.4** and **Autofac.Extensions.DependencyInjection 5.0.1**\n\n### Getting started with ASP.NET Core and Autofac \n\nBefore we start, let's assume that there are some dependencies:\n\n```fsharp\n// ExampleServices.fs\nmodule SomeProject.ExampleServices\n\ntype ICustomLogger =\n    abstract LogInfo : string -\u003e unit\n\ntype IMessageService = abstract SayHello : unit -\u003e unit\n\ntype CustomLogger() =\n    interface ICustomLogger with\n        member _.LogInfo(str) = printfn \"%s\" str\n\ntype MessageService(logger: ICustomLogger) =\n    interface IHelloService with\n        member _.Say(message) = logger.LogInfo message\n\ntype StartupService(messageService: IMessageService) =\n    interface IHostedService with\n        member _.StartAsync(token: CancellationToken) =\n            messageService.Say(\"Hello\")\n            Task.CompletedTask\n\n        member _.StopAsync(_: CancellationToken) =\n            Task.CompletedTask\n```\n\nHere we defined dummy logger, `IMessageService` that uses that logger and `IHostedService` that on start uses our `IMessageService` for writing some stuff.\n\nThen, lets define our dependencies module:\n```fsharp\n// Dependencies.fs\nmodule SomeProject.Dependencies\n\nopen DependX\nopen DependX.Autofac\nopen DependX.AspNetCore\nopen ExampleServices\n\nlet register = dependencies [\n    // ...\n]\n```\n\n`open DependX` - for core types and logic\n\n`open DependX.Autofac` - for autofac-specific interpreter\n\n`open DependX.AspNetCore` - for ASP.NET Core related stuff, in our case - `hostedService` \n\n`let register = dependencies [...]` - this is our initial dependency composition. We will declare dependencies inside that block.\n\nLets add our newly created dependencies:\n\n```fsharp\n// Dependencies.fs\n// ...\nlet register = dependencies [\n    configure contract\u003cICustomLogger, CustomLogger\u003e {\n        lifetime singleton\n    }\n    contract\u003cISomeService, SomeService\u003e\n    hostedService\u003cStartupService\u003e\n]\n```\n\nIn that case we registered `CustomLogger` as singleton and `SomeService` as transient (by default). We also added StartupService as IHostedService just like regular `.AddHostedService` in ASP.NET Core DI.\n\nThat's it. We only need to provide information how dependency need to be registered, **there are no direct usage on Autofac related stuff like ContainerBuilder**.\n\nAfter that we need to use our register function in `Startup.fs` class:\n```fsharp\n// Startup.fs\n// ...\nopen Dependencies\n// ...\ntype Startup(...) =\n    member this.ConfigureContainer(builder: ContainerBuilder) =\n        register builder |\u003e ignore\n```\n\nAnd (if you don't added it yet) configure Autofac in `Program.fs`:\n\n```fsharp\n// ...\nopen DependX.AspNetCore.Autofac\n// ...\n    Host.CreateDefaultBuilder(args)\n        .UseServiceProviderFactory(AutofacServiceProviderFactory()) // ASP.NET Core 3+ related stuff\n        .ConfigureWebHostDefaults(fun webBuilder -\u003e\n            webBuilder.UseStartup\u003cStartup\u003e() |\u003e ignore\n            webBuilder |\u003e configureAutofacDefaults\n        )\n```\n\nAfter project start you will see\n```\nHello\n```\nin the console window. More information about what functions you could use for registratino can be found in **[documentation](DOCUMENTATION.md)**\n\n### Solution structure\n\n#### Core\n- `DependX.Core` - core library with main logic for creating abstract dependencies\n\n#### Autofac\n- `DependX.Autofac` - provides interpret functions that produces Autofac IoC container from abstract dependencies\n\n#### ASP.NET Core extensions\n- `DependX.AspNetCore` - provides helper functions to support injection of ASP.NET Core related services (like IHostedService) \n- `DependX.AspNetCore.Autofac` - provides helper functions to configure and use Autofac in ASP.NET Core\n\n#### Tests\n- `DependX.Tests` - contains unit tests for core logic\n\n### Documentation\n\nYou could found full documentation **[here](DOCUMENTATION.md)**\n\n### Contributing\n\nFeel free to submit issues and PR's. If you have any questions contact me via **[email](mailto:andrewrublyov99@gmail.com)** or **[telegram](https://t.me/FreeParticle)**.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseclerp%2Fdependx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseclerp%2Fdependx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseclerp%2Fdependx/lists"}