{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/DependencyInjection/issues/329","repository_url":"https://api.github.com/repos/aspnet/DependencyInjection","labels_url":"https://api.github.com/repos/aspnet/DependencyInjection/issues/329/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/DependencyInjection/issues/329/comments","events_url":"https://api.github.com/repos/aspnet/DependencyInjection/issues/329/events","html_url":"https://github.com/aspnet/DependencyInjection/issues/329","id":117804659,"node_id":"MDU6SXNzdWUxMTc4MDQ2NTk=","number":329,"title":"Best way to resolve during ConfigureServices","user":{"login":"prasannavl","id":559409,"node_id":"MDQ6VXNlcjU1OTQwOQ==","avatar_url":"https://avatars1.githubusercontent.com/u/559409?v=4","gravatar_id":"","url":"https://api.github.com/users/prasannavl","html_url":"https://github.com/prasannavl","followers_url":"https://api.github.com/users/prasannavl/followers","following_url":"https://api.github.com/users/prasannavl/following{/other_user}","gists_url":"https://api.github.com/users/prasannavl/gists{/gist_id}","starred_url":"https://api.github.com/users/prasannavl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prasannavl/subscriptions","organizations_url":"https://api.github.com/users/prasannavl/orgs","repos_url":"https://api.github.com/users/prasannavl/repos","events_url":"https://api.github.com/users/prasannavl/events{/privacy}","received_events_url":"https://api.github.com/users/prasannavl/received_events","type":"User","site_admin":false},"labels":[{"id":74411369,"node_id":"MDU6TGFiZWw3NDQxMTM2OQ==","url":"https://api.github.com/repos/aspnet/DependencyInjection/labels/question","name":"question","color":"cc317c","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2015-11-19T12:32:17Z","updated_at":"2018-10-16T22:07:18Z","closed_at":"2015-11-19T17:35:36Z","author_association":"NONE","body":"I have a `ConfigureServices` similar to this.\n\n```\npublic IServiceProvider ConfigureServices(IServiceCollection services)\n        {\n            services.AddMvc();\n\n            services.AddSingleton<SomeService>();\n\n           // How do I do this?\n           // services.AddInstance(ctx => new AnotherService(ctx.Resolve<SomeService>()));\n           // This can easily be done when using another container like AutoFac since it provides the\n           // context. However when doing `services.Configure` variants its often not intuitive to\n           // to use the external container. Is there a way something like this could be done inside \n           // service.Configure? \n\n            var builder = new ContainerBuilder();\n\n            Temporals.AutofacRegistration.Populate(builder, services);\n\n            builder.RegisterType<MailClient>()\n                .SingleInstance();\n\n            builder.Register((context => new HttpClient()))\n                .Keyed<HttpClient>(\"ipApi\")\n                .As<HttpClient>()\n                .SingleInstance();\n\n            var container = builder.Build();\n\n\n\n            return container.Resolve<IServiceProvider>();\n        }\n```\n\nThis is especially useful when dealing with Scoped services, which won't be available during the configuration. \n\nIs there a recommended way to do this?\n"},"comment":{"url":"https://api.github.com/repos/aspnet/DependencyInjection/issues/comments/430418177","html_url":"https://github.com/aspnet/DependencyInjection/issues/329#issuecomment-430418177","issue_url":"https://api.github.com/repos/aspnet/DependencyInjection/issues/329","id":430418177,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMDQxODE3Nw==","user":{"login":"Jishun","id":12438914,"node_id":"MDQ6VXNlcjEyNDM4OTE0","avatar_url":"https://avatars2.githubusercontent.com/u/12438914?v=4","gravatar_id":"","url":"https://api.github.com/users/Jishun","html_url":"https://github.com/Jishun","followers_url":"https://api.github.com/users/Jishun/followers","following_url":"https://api.github.com/users/Jishun/following{/other_user}","gists_url":"https://api.github.com/users/Jishun/gists{/gist_id}","starred_url":"https://api.github.com/users/Jishun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jishun/subscriptions","organizations_url":"https://api.github.com/users/Jishun/orgs","repos_url":"https://api.github.com/users/Jishun/repos","events_url":"https://api.github.com/users/Jishun/events{/privacy}","received_events_url":"https://api.github.com/users/Jishun/received_events","type":"User","site_admin":false},"created_at":"2018-10-16T22:07:18Z","updated_at":"2018-10-16T22:07:18Z","author_association":"NONE","body":"I believe this has been addressed for a long time but it seems missing a note here\r\nI my use case, I need to resolve an instance for the DispathProxy so that I created the IServiceProvider from IServiceCollection by `services.BuildServiceProvider();` then it ends up not in control of the same scope, the correct way is to wrap the resolving method call to later when involved by using the IServiceProvider provided by the AddScoped function as \r\n`serviceCollection.AddScoped((provider) => ServiceDispatcher<YourTypeInterface>.Create<YourType>(provider));`\r\nthen inside of the create method it does `YourType instance = provider.GetService<YourType>()`"}}
{"actor":{"display_login":"Jishun"}}