{"action":"created","issue":{"url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/153","labels_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/153/labels{/name}","comments_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/153/comments","events_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/153/events","html_url":"https://github.com/simpleinjector/SimpleInjector/issues/153","id":118641680,"number":153,"title":"Can I execute logic when a dependency instance is first resolved?","user":{"login":"apetkovic","id":1282594,"avatar_url":"https://avatars.githubusercontent.com/u/1282594?v=3","gravatar_id":"","url":"https://api.github.com/users/apetkovic","html_url":"https://github.com/apetkovic","followers_url":"https://api.github.com/users/apetkovic/followers","following_url":"https://api.github.com/users/apetkovic/following{/other_user}","gists_url":"https://api.github.com/users/apetkovic/gists{/gist_id}","starred_url":"https://api.github.com/users/apetkovic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apetkovic/subscriptions","organizations_url":"https://api.github.com/users/apetkovic/orgs","repos_url":"https://api.github.com/users/apetkovic/repos","events_url":"https://api.github.com/users/apetkovic/events{/privacy}","received_events_url":"https://api.github.com/users/apetkovic/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,"milestone":null,"comments":2,"created_at":"2015-11-24T16:04:12Z","updated_at":"2015-11-24T16:59:41Z","closed_at":null,"body":"I've used `OnActivation` and `OnDeactivation` methods in Ninject to execute logic when an instance is first resolved. I checked the documentation and couldn't find anything like that for Simple Injector. I use this for things like handling events that are raised in a specific instance. Is there a way to extend Simple Injector and create this behavior?"},"comment":{"url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/comments/159339089","html_url":"https://github.com/simpleinjector/SimpleInjector/issues/153#issuecomment-159339089","issue_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/153","id":159339089,"user":{"login":"apetkovic","id":1282594,"avatar_url":"https://avatars.githubusercontent.com/u/1282594?v=3","gravatar_id":"","url":"https://api.github.com/users/apetkovic","html_url":"https://github.com/apetkovic","followers_url":"https://api.github.com/users/apetkovic/followers","following_url":"https://api.github.com/users/apetkovic/following{/other_user}","gists_url":"https://api.github.com/users/apetkovic/gists{/gist_id}","starred_url":"https://api.github.com/users/apetkovic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apetkovic/subscriptions","organizations_url":"https://api.github.com/users/apetkovic/orgs","repos_url":"https://api.github.com/users/apetkovic/repos","events_url":"https://api.github.com/users/apetkovic/events{/privacy}","received_events_url":"https://api.github.com/users/apetkovic/received_events","type":"User","site_admin":false},"created_at":"2015-11-24T16:59:41Z","updated_at":"2015-11-24T16:59:41Z","body":"RegisterInitializer should work for me. Just to get a better idea of how I'm using it... \r\n\r\nI have a business logic layer that is shared across a few web applications each using different technologies (mvc, web api, and wcf). My business logic layer doesn't implement any type of exception handling. All exceptions bubble up to the application level, where they are logged by some exception monitoring system (either elmah, raygun, or app insights). There are some scenarios however, where the exception isn't bubbled up due to an asynchronous request or executing logic on a separate thread. In those cases I implement an OnFailure event on the class that fires when an exception is returned. I handle that OnFailure event at the application level where my dependencies are registered (using OnActivation) and the exception monitoring is already configured. \r\n\r\nI suppose to get around this I could inject an IExceptionLogger that implements each of the different exception monitors at the application level. But that now becomes a required dependency. If I don't want to log exceptions I still need to create an empty implementation of IExceptionLogger and inject it."}}