{"action":"created","issue":{"url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/294","repository_url":"https://api.github.com/repos/simpleinjector/SimpleInjector","labels_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/294/labels{/name}","comments_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/294/comments","events_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/294/events","html_url":"https://github.com/simpleinjector/SimpleInjector/issues/294","id":176376903,"number":294,"title":"Factory method with parameter?","user":{"login":"AnderssonPeter","id":1308309,"avatar_url":"https://avatars.githubusercontent.com/u/1308309?v=3","gravatar_id":"","url":"https://api.github.com/users/AnderssonPeter","html_url":"https://github.com/AnderssonPeter","followers_url":"https://api.github.com/users/AnderssonPeter/followers","following_url":"https://api.github.com/users/AnderssonPeter/following{/other_user}","gists_url":"https://api.github.com/users/AnderssonPeter/gists{/gist_id}","starred_url":"https://api.github.com/users/AnderssonPeter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AnderssonPeter/subscriptions","organizations_url":"https://api.github.com/users/AnderssonPeter/orgs","repos_url":"https://api.github.com/users/AnderssonPeter/repos","events_url":"https://api.github.com/users/AnderssonPeter/events{/privacy}","received_events_url":"https://api.github.com/users/AnderssonPeter/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/simpleinjector/SimpleInjector/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-09-12T13:35:30Z","updated_at":"2016-09-13T07:04:56Z","closed_at":null,"body":"Is there any way to have a factory method with a parameter?\r\nLets say i have the following two classes\r\n\r\n```\r\nOrganisation (OrganisationContext organisationContext, string name)\r\nOrganisationContext (Func<OrganisationContext, Organisation, string> organisationFactory)\r\n```\r\n\r\nHow would i register this in SimpleInjector so that i get a method injected into `OrganisationContext` that can be called with a `OrganisationContext` and string parameter to create a `Organisation` with the parameters passed to the function into the constructor?\r\n\r\nOr is this simply not possible, if that is the case should i just add a initialize method and pass the parameters there?\r\n\r\nOr am i missing something about how to use DI?"},"comment":{"url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/comments/246593658","html_url":"https://github.com/simpleinjector/SimpleInjector/issues/294#issuecomment-246593658","issue_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/294","id":246593658,"user":{"login":"dotnetjunkie","id":1506621,"avatar_url":"https://avatars.githubusercontent.com/u/1506621?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnetjunkie","html_url":"https://github.com/dotnetjunkie","followers_url":"https://api.github.com/users/dotnetjunkie/followers","following_url":"https://api.github.com/users/dotnetjunkie/following{/other_user}","gists_url":"https://api.github.com/users/dotnetjunkie/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnetjunkie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnetjunkie/subscriptions","organizations_url":"https://api.github.com/users/dotnetjunkie/orgs","repos_url":"https://api.github.com/users/dotnetjunkie/repos","events_url":"https://api.github.com/users/dotnetjunkie/events{/privacy}","received_events_url":"https://api.github.com/users/dotnetjunkie/received_events","type":"User","site_admin":false},"created_at":"2016-09-13T07:04:56Z","updated_at":"2016-09-13T07:04:56Z","body":"You can do the registration as follows:\r\n\r\n``` c#\r\nvar database = new Database();\r\n\r\ncontainer.RegisterSingleton(database);\r\ncontainer.Register<Organisation>(() => new Organisation(\r\n    database, \r\n    (o, name) => new Member(database, o, name)));\r\n```\r\n\r\nBut again, I would urge you to change your design. Prevent constructor injection into entities. Prevent doing any considerable logic into constructors. Apply the repository pattern instead of letting entities query the database them selves. Refrain from using the Active Record pattern. These tips will guide you to a cleaner, more maintainable design and simplify constructing your object graphs; whether you apply DI  by hand (a.k.a. Pure DI) or whether you use a container to do so."}}
{"actor":{"display_login":"dotnetjunkie"}}