{"id":18249572,"url":"https://github.com/unitycontainer/microsoft-dependency-injection","last_synced_at":"2025-04-04T16:30:45.748Z","repository":{"id":56140356,"uuid":"107613001","full_name":"unitycontainer/microsoft-dependency-injection","owner":"unitycontainer","description":"Unity.Microsoft.DependencyInjection package","archived":false,"fork":false,"pushed_at":"2024-05-12T14:08:23.000Z","size":157,"stargazers_count":63,"open_issues_count":20,"forks_count":36,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-16T09:36:38.940Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/unitycontainer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["ENikS"],"open_collective":"unity-container"}},"created_at":"2017-10-20T00:31:08.000Z","updated_at":"2025-01-16T09:31:10.000Z","dependencies_parsed_at":"2024-11-05T09:42:57.589Z","dependency_job_id":"d07fc39c-9e53-4df6-911c-c44ffbf77164","html_url":"https://github.com/unitycontainer/microsoft-dependency-injection","commit_stats":null,"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unitycontainer%2Fmicrosoft-dependency-injection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unitycontainer%2Fmicrosoft-dependency-injection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unitycontainer%2Fmicrosoft-dependency-injection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unitycontainer%2Fmicrosoft-dependency-injection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unitycontainer","download_url":"https://codeload.github.com/unitycontainer/microsoft-dependency-injection/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247209231,"owners_count":20901730,"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-05T09:40:33.529Z","updated_at":"2025-04-04T16:30:45.742Z","avatar_url":"https://github.com/unitycontainer.png","language":"C#","funding_links":["https://github.com/sponsors/ENikS","https://opencollective.com/unity-container"],"categories":[],"sub_categories":[],"readme":"[![Build status](https://ci.appveyor.com/api/projects/status/sevk2yb2jokf8ltr/branch/master?svg=true)](https://ci.appveyor.com/project/IoC-Unity/microsoft-dependency-injection/branch/master)\n[![License](https://img.shields.io/badge/license-apache%202.0-60C060.svg)](https://github.com/IoC-Unity/microsoft-dependency-injection/blob/master/LICENSE)\n[![NuGet](https://img.shields.io/nuget/dt/Unity.Microsoft.DependencyInjection.svg)](https://www.nuget.org/packages/Unity.Microsoft.DependencyInjection)\n[![NuGet](https://img.shields.io/nuget/v/Unity.Microsoft.DependencyInjection.svg)](https://www.nuget.org/packages/Unity.Microsoft.DependencyInjection)\n\n# Unity.Microsoft.DependencyInjection\n\nUnity extension to integrate with [Microsoft.Extensions.DependencyInjection](https://github.com/aspnet/DependencyInjection)  compliant systems\n\n## Getting Started\n\n- Reference the `Unity.Microsoft.DependencyInjection` package from NuGet.\n\n```shell\nInstall-Package Unity.Microsoft.DependencyInjection\n```\n\n## Registration:\n\n- In the `WebHostBuilder` add `UseUnityServiceProvider(...)` method\n\n```C#\npublic static IHostBuilder CreateHostBuilder(string[] args) =\u003e\n    Host.CreateDefaultBuilder(args)\n        .UseUnityServiceProvider()   \u003c---- Add this line\n        .ConfigureWebHostDefaults(webBuilder =\u003e\n        {\n            webBuilder.UseStartup\u003cStartup\u003e();\n        });\n```\n\n- In case Unity container configured via application configuration or by convention this container could be used to initialize service provider.\n\n```C#\npublic static IHostBuilder CreateHostBuilder(string[] args) =\u003e\n    Host.CreateDefaultBuilder(args)\n        .UseUnityServiceProvider(_container)   //\u003c---- Add this line\n        .ConfigureWebHostDefaults(webBuilder =\u003e\n        {\n            webBuilder.UseStartup\u003cStartup\u003e();\n        });\n```\n\n- Add optional method to your `Startup` class\n\n```C#\npublic void ConfigureContainer(IUnityContainer container)\n{\n  // Could be used to register more types\n  container.RegisterType\u003cIMyService, MyService\u003e();\n}\n```\n\n### Resolving Controllers from Unity\n\nBy default ASP resolves controllers using built in activator. To enable resolution of controllers from Unity you need to add following line to MVC configuration:\n\n```C#\npublic void ConfigureServices(IServiceCollection services)\n{\n    ...\n    services.AddMvc()\n        .AddControllersAsServices()  //\u003c-- Add this line\n        .SetCompatibilityVersion(CompatibilityVersion.Version_3_0)\n    ...\n}\n```\n\n## Examples\n\nFor example of using Unity with Core 3.1 Web application follow [this link](https://github.com/unitycontainer/examples/tree/master/src/web/ASP.Net.Unity.Example)\n\n## Code of Conduct\n\nThis project has adopted the code of conduct defined by the [Contributor Covenant](https://www.contributor-covenant.org/) to clarify expected behavior in our community. For more information, see the [.NET Foundation Code of Conduct](https://www.dotnetfoundation.org/code-of-conduct)\n\n## Contributing\n\nSee the [Contributing guide](https://github.com/unitycontainer/unity/blob/master/CONTRIBUTING.md) for more information.\n\n## .NET Foundation\n\nUnity Container is a [.NET Foundation](https://dotnetfoundation.org/projects/unitycontainer) project\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funitycontainer%2Fmicrosoft-dependency-injection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funitycontainer%2Fmicrosoft-dependency-injection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funitycontainer%2Fmicrosoft-dependency-injection/lists"}