{"id":21244780,"url":"https://github.com/fiddlydigital/autofaccirculardependencyresolution","last_synced_at":"2025-03-15T04:25:53.328Z","repository":{"id":176548370,"uuid":"367941950","full_name":"FiddlyDigital/AutofacCircularDependencyResolution","owner":"FiddlyDigital","description":"How to resolve Circular Dependencies in using Autofac DI - without needing to perform massive refactoring effort.","archived":false,"fork":false,"pushed_at":"2021-05-16T17:17:05.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-21T20:12:56.236Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FiddlyDigital.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2021-05-16T17:12:52.000Z","updated_at":"2021-05-16T17:21:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"207bbd75-07e4-4674-83c8-d650dd0ed624","html_url":"https://github.com/FiddlyDigital/AutofacCircularDependencyResolution","commit_stats":null,"previous_names":["fiddlydigital/autofaccirculardependencyresolution"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FiddlyDigital%2FAutofacCircularDependencyResolution","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FiddlyDigital%2FAutofacCircularDependencyResolution/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FiddlyDigital%2FAutofacCircularDependencyResolution/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FiddlyDigital%2FAutofacCircularDependencyResolution/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FiddlyDigital","download_url":"https://codeload.github.com/FiddlyDigital/AutofacCircularDependencyResolution/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243684437,"owners_count":20330862,"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","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":[],"created_at":"2024-11-21T01:30:48.774Z","updated_at":"2025-03-15T04:25:53.306Z","avatar_url":"https://github.com/FiddlyDigital.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# Resolve Autofac Circular Dependencies (without massive refactoring)\n\nThis project is a working example of how to overcome circular dependenices using Autofac DI.\n\nI came across this issue recently during massive refactoring effort on a large codebase. I didn't have the time to go ahead and correctly split and refactor all classes, so did some searching and found a great solution proposed by Thomas Levesque.\n\nThe solution is that instead of rewriting all of your logic, you can Lazily resolve dependencies when used - not when they're injected into the constructor.\nIts more of a band-aid rather than a long-term fix, but it can get you out of trouble during an interim refactoring step.\n\n## Steps\n\n1. Implement the _ServiceCollectionExtensions_ in your project _(Extensions\\ServiceCollectionExtensions.cs)_\n2. Add LazyResolution to your ServiceProvider _(See Program.cs)_\n3. Wrap required Interfaces with _Lazy\u003c\u003e_ both:\n   1. When defined: ```private readonly Lazy\u003cIItemTestManager\u003e _itemTestManager;```\n   2. When injected: ```public ItemManager(Lazy\u003cIItemTestManager\u003e itemTestManager)```\n   3. See _ItemManager_ and _ItemTestManager_ for example usage\n4. Use ```\u003cT\u003e.Value.``` to call methods on the LazilyInjected item\n   1. e.g. ```_itemTestManager.Value.Test(items);```\n\n## Notes\n\n* Don't access the _Lazy\u003c\u003e_ injected classes in the Constructor of the Injectee!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffiddlydigital%2Fautofaccirculardependencyresolution","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffiddlydigital%2Fautofaccirculardependencyresolution","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffiddlydigital%2Fautofaccirculardependencyresolution/lists"}