{"id":17336310,"url":"https://github.com/alsami/automapper.contrib.autofac.dependencyinjection","last_synced_at":"2025-10-18T08:00:28.211Z","repository":{"id":45148263,"uuid":"186964650","full_name":"alsami/AutoMapper.Contrib.Autofac.DependencyInjection","owner":"alsami","description":"Autofac plug-in for AutoMapper.","archived":false,"fork":false,"pushed_at":"2024-02-23T10:44:46.000Z","size":85,"stargazers_count":20,"open_issues_count":1,"forks_count":10,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-31T04:48:10.682Z","etag":null,"topics":["autofac","autofac-container","automapper","ioc","object-to-object"],"latest_commit_sha":null,"homepage":"","language":"C#","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/alsami.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-16T06:24:36.000Z","updated_at":"2024-10-29T16:02:15.000Z","dependencies_parsed_at":"2023-01-23T02:31:01.276Z","dependency_job_id":null,"html_url":"https://github.com/alsami/AutoMapper.Contrib.Autofac.DependencyInjection","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alsami%2FAutoMapper.Contrib.Autofac.DependencyInjection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alsami%2FAutoMapper.Contrib.Autofac.DependencyInjection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alsami%2FAutoMapper.Contrib.Autofac.DependencyInjection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alsami%2FAutoMapper.Contrib.Autofac.DependencyInjection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alsami","download_url":"https://codeload.github.com/alsami/AutoMapper.Contrib.Autofac.DependencyInjection/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223639403,"owners_count":17177816,"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":["autofac","autofac-container","automapper","ioc","object-to-object"],"created_at":"2024-10-15T15:29:15.647Z","updated_at":"2025-10-18T08:00:28.128Z","avatar_url":"https://github.com/alsami.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AutoMapper.Contrib.Autofac.DependencyInjection\n\n[![Build Application](https://github.com/alsami/AutoMapper.Contrib.Autofac.DependencyInjection/actions/workflows/push.yml/badge.svg?branch=main\u0026event=push)](https://github.com/alsami/AutoMapper.Contrib.Autofac.DependencyInjection/actions/workflows/push.yml)\n[![codecov](https://codecov.io/gh/alsami/AutoMapper.Contrib.Autofac.DependencyInjection/branch/main/graph/badge.svg)](https://codecov.io/gh/alsami/AutoMapper.Contrib.Autofac.DependencyInjection)\n\n[![NuGet](https://img.shields.io/nuget/dt/AutoMapper.Contrib.Autofac.DependencyInjection.svg)](https://www.nuget.org/packages/AutoMapper.Contrib.Autofac.DependencyInjection) \n[![NuGet](https://img.shields.io/nuget/vpre/AutoMapper.Contrib.Autofac.DependencyInjection.svg)](https://www.nuget.org/packages/AutoMapper.Contrib.Autofac.DependencyInjection)\n\nThis is a cross platform library, written in .netstandard 2.0, that serves as an extension for [autofac's containerbuilder](https://autofac.org/).\nIt will register all necessary classes and interfaces of Jimmy Bogard's [AutoMapper](https://github.com/AutoMapper/AutoMapper) implementation to the autofac-container \nso you can use AutoMapper and object-mapping right ahead without worrying about setting up required infrastructure code.\n\n## Installation\n\nThis package is available via nuget. You can install it using Visual-Studio-Nuget-Browser or by using the dotnet-cli\n\n```\ndotnet add package AutoMapper.Contrib.Autofac.DependencyInjection\n```\n\nIf you want to add a specific version of this package\n\n```\ndotnet add package AutoMapper.Contrib.Autofac.DependencyInjection --version 1.0.0\n```\n\nFor more information please visit the official [dotnet-cli documentation](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-add-package).\n\n## Usage sample\n\nAfter installing the package you define your entities and dtos and create profiles for them.\n\n```csharp\npublic class Customer\n{\n\tpublic Guid Id { get; }\n\tpublic string Name { get; }\n\t\n\tpublic Customer(Guid id, string name)\n\t{\n\t\tId = id;\n\t\tName = name;\n\t}\n}\n\npublic class CustomerDto\n{\n\tpublic Guid Id { get; }\n\tpublic string Name { get; }\n\n\tpublic CustomerDto(Guid id, string name)\n\t{\n\t\tId = id;\n\t\tName = name;\n\t}\n}\n\npublic class CustomerProfile : Profile \n{\n\tpublic CustomerProfile()\n\t{\n\t\tCreateMap\u003cCustomer, CustomerDto\u003e()\n\t\t\t.ConstructUsing(user =\u003e new UserDto(user.Id, user.Name))\n\t\t\t.ReverseMap()\n\t\t\t.ConstructUsing(userDto =\u003e new User(userDto.Id, userDto.Name));\n\t}\n}\n\npublic static class Program\n{\n\tpublic static void Main(string args[])\n\t{\n\t\tvar containerBuilder = new ContainerBuilder();\n\t\t// here you have to pass in the assembly (or assemblies) containing AutoMapper types\n\t\t// stuff like profiles, resolvers and type-converters will be added by this function\n\t\tcontainerBuilder.RegisterAutoMapper(typeof(Program).Assembly);\n\t\t\n\t\tvar container = containerBuilder.Build();\n\n\t\tvar mapper = container.Resolve\u003cIMapper\u003e();\n\n\t\tvar customer = new Customer(Guid.NewGuid(), \"Google\");\n\n\t\tvar customerDto = mapper.Map\u003cCustomerDto\u003e(customer);\n\t}\n}\n```\n\n### Support for Property Injection\n\nYou can set `propertiesAutowired` to true to enable property based injection, just modify the prior example like so:\n\n```csharp\npublic static class Program\n{\n\tpublic static void Main(string args[])\n\t{\n\t\tvar containerBuilder = new ContainerBuilder();\n\t\t\n\t\t// Update this line with the setting:\n\t\tcontainerBuilder.RegisterAutoMapper(typeof(Program).Assembly, propertiesAutowired: true);\n\t\t\n\t\tvar container = containerBuilder.Build();\n\n\t\tvar mapper = container.Resolve\u003cIMapper\u003e();\n\n\t\tvar customer = new Customer(Guid.NewGuid(), \"Google\");\n\n\t\tvar customerDto = mapper.Map\u003cCustomerDto\u003e(customer);\n\t}\n}\n```\n\n### Validating your configuration\n\n`AutoMapper` allows the user to validate their mappings. **This should only be done within a test project, since it's time-consuming**\n\n```csharp\nvar containerBuilder = new ContainerBuilder();\ncontainerBuilder.RegisterAutoMapper(typeof(Program).Assembly);\n\nvar container = containerBuilder.Build();\nvar mapperConfiguration = container.Resolve\u003cMapperConfiguration\u003e();\n\n// this line will throw when mappings are not working as expected\n// it's wise to write a test for that, which is always executed within a CI pipeline for your project.\nmapperConfiguration.AssertConfigurationIsValid();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falsami%2Fautomapper.contrib.autofac.dependencyinjection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falsami%2Fautomapper.contrib.autofac.dependencyinjection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falsami%2Fautomapper.contrib.autofac.dependencyinjection/lists"}