{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/12403","repository_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore","labels_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/12403/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/12403/comments","events_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/12403/events","html_url":"https://github.com/aspnet/EntityFrameworkCore/issues/12403","id":333465748,"node_id":"MDU6SXNzdWUzMzM0NjU3NDg=","number":12403,"title":"Dependency Injection into DbContext for HasData Seed Data","user":{"login":"wadebee","id":81402,"node_id":"MDQ6VXNlcjgxNDAy","avatar_url":"https://avatars3.githubusercontent.com/u/81402?v=4","gravatar_id":"","url":"https://api.github.com/users/wadebee","html_url":"https://github.com/wadebee","followers_url":"https://api.github.com/users/wadebee/followers","following_url":"https://api.github.com/users/wadebee/following{/other_user}","gists_url":"https://api.github.com/users/wadebee/gists{/gist_id}","starred_url":"https://api.github.com/users/wadebee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wadebee/subscriptions","organizations_url":"https://api.github.com/users/wadebee/orgs","repos_url":"https://api.github.com/users/wadebee/repos","events_url":"https://api.github.com/users/wadebee/events{/privacy}","received_events_url":"https://api.github.com/users/wadebee/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-06-18T23:09:28Z","updated_at":"2018-06-19T02:05:10Z","closed_at":null,"author_association":"NONE","body":"I currently have a DbContextInitializer class that loads my seed data from json files. This initializer has a dependency on IFileProvider. It all works fine now with an Initialize method that seeds like this:\r\n`            \r\nif (!Context.EntitySet.Any())\r\n            {\r\n                Context.EntitySet.AddRange(GetSeedData());\r\n                Context.SaveChanges();\r\n            }\r\n`\r\nI wanted to try to convert this over to the new EFCore 2.1 HasData implementation. However it seems HasData calls are scope-limited to the DbContext OnModelCreating event handler. \r\n\r\nIt would be great if I could attach my DbInitializer (or even just the IFileProvider) to my DbContextOptions where I can attach it from the DbContext constructor to a member field making it accessible to OnModelCreating. \r\n\r\nHowever I don't see a way to attach anything to DbContextOptions and I can't find a way to inject anything into my DbContext derived class constructor.\r\n\r\nAm I missing something? "},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/comments/398250996","html_url":"https://github.com/aspnet/EntityFrameworkCore/issues/12403#issuecomment-398250996","issue_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/12403","id":398250996,"node_id":"MDEyOklzc3VlQ29tbWVudDM5ODI1MDk5Ng==","user":{"login":"wadebee","id":81402,"node_id":"MDQ6VXNlcjgxNDAy","avatar_url":"https://avatars3.githubusercontent.com/u/81402?v=4","gravatar_id":"","url":"https://api.github.com/users/wadebee","html_url":"https://github.com/wadebee","followers_url":"https://api.github.com/users/wadebee/followers","following_url":"https://api.github.com/users/wadebee/following{/other_user}","gists_url":"https://api.github.com/users/wadebee/gists{/gist_id}","starred_url":"https://api.github.com/users/wadebee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wadebee/subscriptions","organizations_url":"https://api.github.com/users/wadebee/orgs","repos_url":"https://api.github.com/users/wadebee/repos","events_url":"https://api.github.com/users/wadebee/events{/privacy}","received_events_url":"https://api.github.com/users/wadebee/received_events","type":"User","site_admin":false},"created_at":"2018-06-19T02:05:10Z","updated_at":"2018-06-19T02:05:10Z","author_association":"NONE","body":"Normal constructor injection fails with code migrations.\n\nGet Outlook for iOS<https://aka.ms/o0ukef>\n_____________________________\nFrom: Arthur Vickers <notifications@github.com>\nSent: Monday, June 18, 2018 8:04 PM\nSubject: Re: [aspnet/EntityFrameworkCore] Dependency Injection into DbContext for HasData Seed Data (#12403)\nTo: aspnet/EntityFrameworkCore <entityframeworkcore@noreply.github.com>\nCc: Wade Bee <wadebee@hotmail.com>, Mention <mention@noreply.github.com>\n\n\n\n@wadebee<https://github.com/wadebee> You can use normal constructor injection on the derived DbContext type.\n\n—\nYou are receiving this because you were mentioned.\nReply to this email directly, view it on GitHub<https://github.com/aspnet/EntityFrameworkCore/issues/12403#issuecomment-398232686>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AAE9-iqmNL3ZT8fZaNCL8rYDQe8OI6qdks5t-EAUgaJpZM4UsnCV>.\n\n\n"}}
{"actor":{"display_login":"wadebee"}}