{"action":"opened","issue":{"url":"https://api.github.com/repos/seesharper/LightInject/issues/328","repository_url":"https://api.github.com/repos/seesharper/LightInject","labels_url":"https://api.github.com/repos/seesharper/LightInject/issues/328/labels{/name}","comments_url":"https://api.github.com/repos/seesharper/LightInject/issues/328/comments","events_url":"https://api.github.com/repos/seesharper/LightInject/issues/328/events","html_url":"https://github.com/seesharper/LightInject/issues/328","id":188476555,"number":328,"title":"Resolve dependencies through xml or web.config file","user":{"login":"Aeptitude","id":23378462,"avatar_url":"https://avatars.githubusercontent.com/u/23378462?v=3","gravatar_id":"","url":"https://api.github.com/users/Aeptitude","html_url":"https://github.com/Aeptitude","followers_url":"https://api.github.com/users/Aeptitude/followers","following_url":"https://api.github.com/users/Aeptitude/following{/other_user}","gists_url":"https://api.github.com/users/Aeptitude/gists{/gist_id}","starred_url":"https://api.github.com/users/Aeptitude/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aeptitude/subscriptions","organizations_url":"https://api.github.com/users/Aeptitude/orgs","repos_url":"https://api.github.com/users/Aeptitude/repos","events_url":"https://api.github.com/users/Aeptitude/events{/privacy}","received_events_url":"https://api.github.com/users/Aeptitude/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-11-10T10:51:11Z","updated_at":"2016-11-10T10:51:11Z","closed_at":null,"body":"This is a continuation of this question raised via SO a few weeks ago\r\n\r\nhttp://stackoverflow.com/questions/39832959/resolve-dependency-through-xml-file-or-web-config-using-lightinject\r\n\r\nWhat I would like to do is register the dependencies lightinject uses through an XML file or some external config file. The use case I'm looking to implement would be for websites and non web applications. This is for internal projects so when we introduce new versions, the implementations can be swapped out very simply. \r\n\r\nIn the previous discussion I'd been told to use Type.GetType(typeName) \r\n\r\nHere is my method to do this;\r\n\r\n`public static T GetFromConfig<T>() where T : class\r\n        {\r\n            string typeName = WebConfigurationManager.AppSettings[typeof (T).ToString()];\r\n            if (string.IsNullOrEmpty(typeName))\r\n            {\r\n                return null;\r\n            }\r\n            Type repoType = Type.GetType(typeName);\r\n            object repoInstance = Activator.CreateInstance(repoType);\r\n            T repo = repoInstance as T;\r\n            return repo;\r\n        }`\r\n\r\n\r\nThis is the snippet of my controller;\r\n\r\n` public class MyServicesApiController : ApiController\r\n    {\r\n        private readonly IPersonRepository _repository;\r\n        public MyServicesApiController()\r\n        {         \r\n            _repository = SimpleContainer.GetFromConfig<IPersonRepository>();}}`\r\n\r\n\r\nmy web.config (using this for now, wanting to use an xml file next) contains the following key\r\n\r\n`<appSettings>\r\n    <add key=\"PersonRepository.Interface.IPersonRepository\" value=\"PersonRepository.Db.DbRepository,PersonRepository.Db, Version=1.0.0.0, Culture=neutral\" />\r\n  </appSettings>`\r\n\r\nUsing this method, The compiler  gives the error \" 'repoType ' is a variable, but is used like a type.\"\r\n\r\nUpon further reading I found this \r\nhttp://stackoverflow.com/questions/302577/how-to-use-typeof-or-gettype-as-generics-template\r\n\r\nSuggesting this typing is limited by the constraints of the language.\r\n\r\nI've noted that this can be done with other containers, but was hoping this was something that could be done with lightInject?\r\n\r\nThanks very much. "}}
{"actor":{"display_login":"Aeptitude"}}