{"action":"created","issue":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper.Extensions.Microsoft.DependencyInjection/issues/36","repository_url":"https://api.github.com/repos/AutoMapper/AutoMapper.Extensions.Microsoft.DependencyInjection","labels_url":"https://api.github.com/repos/AutoMapper/AutoMapper.Extensions.Microsoft.DependencyInjection/issues/36/labels{/name}","comments_url":"https://api.github.com/repos/AutoMapper/AutoMapper.Extensions.Microsoft.DependencyInjection/issues/36/comments","events_url":"https://api.github.com/repos/AutoMapper/AutoMapper.Extensions.Microsoft.DependencyInjection/issues/36/events","html_url":"https://github.com/AutoMapper/AutoMapper.Extensions.Microsoft.DependencyInjection/issues/36","id":274157346,"number":36,"title":"Extension Doesn't Work with AutoMapper 6.2.0 In Integration Tests","user":{"login":"adamrodger","id":508586,"avatar_url":"https://avatars0.githubusercontent.com/u/508586?v=4","gravatar_id":"","url":"https://api.github.com/users/adamrodger","html_url":"https://github.com/adamrodger","followers_url":"https://api.github.com/users/adamrodger/followers","following_url":"https://api.github.com/users/adamrodger/following{/other_user}","gists_url":"https://api.github.com/users/adamrodger/gists{/gist_id}","starred_url":"https://api.github.com/users/adamrodger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamrodger/subscriptions","organizations_url":"https://api.github.com/users/adamrodger/orgs","repos_url":"https://api.github.com/users/adamrodger/repos","events_url":"https://api.github.com/users/adamrodger/events{/privacy}","received_events_url":"https://api.github.com/users/adamrodger/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper.Extensions.Microsoft.DependencyInjection/milestones/1","html_url":"https://github.com/AutoMapper/AutoMapper.Extensions.Microsoft.DependencyInjection/milestone/1","labels_url":"https://api.github.com/repos/AutoMapper/AutoMapper.Extensions.Microsoft.DependencyInjection/milestones/1/labels","id":2916951,"number":1,"title":"3.2.0","description":null,"creator":{"login":"jbogard","id":104498,"avatar_url":"https://avatars1.githubusercontent.com/u/104498?v=4","gravatar_id":"","url":"https://api.github.com/users/jbogard","html_url":"https://github.com/jbogard","followers_url":"https://api.github.com/users/jbogard/followers","following_url":"https://api.github.com/users/jbogard/following{/other_user}","gists_url":"https://api.github.com/users/jbogard/gists{/gist_id}","starred_url":"https://api.github.com/users/jbogard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbogard/subscriptions","organizations_url":"https://api.github.com/users/jbogard/orgs","repos_url":"https://api.github.com/users/jbogard/repos","events_url":"https://api.github.com/users/jbogard/events{/privacy}","received_events_url":"https://api.github.com/users/jbogard/received_events","type":"User","site_admin":false},"open_issues":0,"closed_issues":2,"state":"closed","created_at":"2017-11-16T12:24:00Z","updated_at":"2017-11-16T12:52:46Z","due_on":null,"closed_at":"2017-11-16T12:52:46Z"},"comments":18,"created_at":"2017-11-15T13:32:25Z","updated_at":"2018-02-12T11:15:17Z","closed_at":"2017-11-16T12:37:02Z","author_association":"NONE","body":"When [integration testing with ASP.Net Core](https://docs.microsoft.com/en-us/aspnet/core/testing/integration-testing), it is very common to use `TestServer` to start your service as an in-memory host so that you can perform service-level integration tests via a real `HttpClient`.\r\n\r\nHowever, since AutoMapper 6.2.0 was released this no longer works. Your `Startup` class is effectively called multiple times within the same process, so the `AddAutoMapper()` call happens multiple times, so the `Mapper.Initialize()` call also happens multiple times. This results in an exception in the second test:\r\n\r\n```\r\nSystem.InvalidOperationException : Mapper already initialized. You must call Initialize once per application domain/process.\r\n   at AutoMapper.Mapper.set_Configuration(IConfigurationProvider value)\r\n   at AutoMapper.Mapper.Initialize(Action`1 config)\r\n   at AutoMapper.ServiceCollectionExtensions.AddAutoMapperClasses(IServiceCollection services, Action`1 additionalInitAction, IEnumerable`1 assemblies)\r\n   at MyService.Startup.ConfigureServices(IServiceCollection services)\r\n```\r\n\r\nHow can we 'clear out' the AutoMapper statics so that integration testing can be supported in a single process?"},"comment":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper.Extensions.Microsoft.DependencyInjection/issues/comments/364893481","html_url":"https://github.com/AutoMapper/AutoMapper.Extensions.Microsoft.DependencyInjection/issues/36#issuecomment-364893481","issue_url":"https://api.github.com/repos/AutoMapper/AutoMapper.Extensions.Microsoft.DependencyInjection/issues/36","id":364893481,"user":{"login":"erikaspl","id":632116,"avatar_url":"https://avatars1.githubusercontent.com/u/632116?v=4","gravatar_id":"","url":"https://api.github.com/users/erikaspl","html_url":"https://github.com/erikaspl","followers_url":"https://api.github.com/users/erikaspl/followers","following_url":"https://api.github.com/users/erikaspl/following{/other_user}","gists_url":"https://api.github.com/users/erikaspl/gists{/gist_id}","starred_url":"https://api.github.com/users/erikaspl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erikaspl/subscriptions","organizations_url":"https://api.github.com/users/erikaspl/orgs","repos_url":"https://api.github.com/users/erikaspl/repos","events_url":"https://api.github.com/users/erikaspl/events{/privacy}","received_events_url":"https://api.github.com/users/erikaspl/received_events","type":"User","site_admin":false},"created_at":"2018-02-12T11:15:17Z","updated_at":"2018-02-12T11:15:17Z","author_association":"NONE","body":"@sm-g [SetUp] and [TearDown] will work as well:\r\n\r\n```  \r\n    public void Configure(IApplicationBuilder app, IHostingEnvironment env, \r\n            ILoggerFactory loggerFactory, IApplicationLifetime applicationLifetime)\r\n    {\r\n         .....\r\n         applicationLifetime.ApplicationStopped.Register(() => AutoMapper.Mapper.Reset());\r\n    }\r\n```\r\n\r\n```      \r\n        protected TestServer Server;\r\n        [SetUp]\r\n        public void OneTimeBaseSetUp()\r\n        {\r\n             Server = new TestServer(....\r\n        }\r\n\r\n        [TearDown]\r\n        public void OneTimeBaseTearDown()\r\n        {\r\n            Server.Dispose();\r\n        }\r\n```"}}
{"actor":{"display_login":"erikaspl"}}