{"action":"created","comment":{"url":"https://api.github.com/repos/Particular/docs.particular.net/pulls/comments/32731713","id":32731713,"diff_hunk":"@@ -0,0 +1,113 @@\n+---\n+title: Managing IBus instance\n+summary: Fluent configuration API to get transnational one-way messaging\n+tags:\n+- Hosting\n+- IOC\n+- Dependency Injection\n+- Service Locator\n+---\n+\n+\n+When you have created a `IBus` instances then you must register it somewhere so that your application can use it to send messages.\n+\n+There are various ways in managing and storing the `IBus` instance.\n+\n+* Global static\n+* Using dependency injection\n+\n+The first option creates tight coupling the last loose coupling.\n+\n+\n+\n+## Global static\n+\n+After you have created the bus you assign the object to a global static variable so that the bus can be used in other locations\n+\n+\n+Initializing:\n+\n+```\n+public class Global\n+{\n+    public static IBus Bus { get; set; }\n+}\n+\n+Global.Bus = NServiceBus.Create(busConfiguration).Start();\n+```\n+\n+Using it:\n+\n+```\n+Global.Bus.Send(new MyCommand());\n+```\n+\n+Cleanup:\n+\n+```\n+Global.Bus.Dispose();\n+```\n+\n+This is very simple to use but creates a lot of tight coupling which makes unit testig pretty hard.\n+\n+## Dependency injection container\n+\n+Here is the description of the dependency injection pattern:\n+\n+>In software engineering, dependency injection is a software design pattern that implements inversion of control for software libraries. Caller delegates to an external framework the control flow of discovering and importing a service or software module specified or \"injected\" by the caller.\n+\n+Source: https://nl.wikipedia.org/wiki/Dependency_injection\n+\n+\n+### Registering\n+\n+When you have created the `IBus` instance then you need to register it in a dependency injection container so that it knows what and how it can inject it into objects that require an `IBus` instance.\n+\n+### Single instance\n+\n+The following example uses Autofac but looks very similar with other frameworks\n+\n+\n+Registering bus instance:\n+```\n+ContainerBuilder builder = new ContainerBuilder();\n+builder.RegisterInstance(bus);\n+IContainer container = builder.Build();\n+```\n+\n+This will make sure that when a object is created via the container and it is dependent on `IBus` that this instance will be injected.\n+\n+NServiceBus will still use its own container to resolve its own objects. NServiceBus can also use an external container.\n+\n+See: [Containers](/nservicebus/containers/index.md)\n+\n+You need to use this when you want types that are registered in the external controller to be injected in to objects created by NServiceBus like message handlers and message mutators.\n+\n+\n+\n+### Disposing\n+\n+When the application done it only needs to dispose the container. The container should take care of disposing all objects in the correct order.\n+\n+There should be no need in calling `IBus.Dispose` when you have registered the bus instance in the container.","path":"nservicebus/hosting/ibus-instance.md","position":92,"original_position":92,"commit_id":"4b5636d9762a8254faa24394da7b810e1c8ba26b","original_commit_id":"4b5636d9762a8254faa24394da7b810e1c8ba26b","user":{"login":"pashute","id":1774131,"avatar_url":"https://avatars.githubusercontent.com/u/1774131?v=3","gravatar_id":"","url":"https://api.github.com/users/pashute","html_url":"https://github.com/pashute","followers_url":"https://api.github.com/users/pashute/followers","following_url":"https://api.github.com/users/pashute/following{/other_user}","gists_url":"https://api.github.com/users/pashute/gists{/gist_id}","starred_url":"https://api.github.com/users/pashute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pashute/subscriptions","organizations_url":"https://api.github.com/users/pashute/orgs","repos_url":"https://api.github.com/users/pashute/repos","events_url":"https://api.github.com/users/pashute/events{/privacy}","received_events_url":"https://api.github.com/users/pashute/received_events","type":"User","site_admin":false},"body":"replace: there should be ... in calling\r\nwith: There is no need to call 'IBus.Dispose' after registering the bus instance in the container.","created_at":"2015-06-18T13:55:45Z","updated_at":"2015-06-18T13:55:45Z","html_url":"https://github.com/Particular/docs.particular.net/pull/675#discussion_r32731713","pull_request_url":"https://api.github.com/repos/Particular/docs.particular.net/pulls/675","_links":{"self":{"href":"https://api.github.com/repos/Particular/docs.particular.net/pulls/comments/32731713"},"html":{"href":"https://github.com/Particular/docs.particular.net/pull/675#discussion_r32731713"},"pull_request":{"href":"https://api.github.com/repos/Particular/docs.particular.net/pulls/675"}}},"pull_request":{"url":"https://api.github.com/repos/Particular/docs.particular.net/pulls/675","id":37914037,"html_url":"https://github.com/Particular/docs.particular.net/pull/675","diff_url":"https://github.com/Particular/docs.particular.net/pull/675.diff","patch_url":"https://github.com/Particular/docs.particular.net/pull/675.patch","issue_url":"https://api.github.com/repos/Particular/docs.particular.net/issues/675","number":675,"state":"open","locked":false,"title":"Extended doco on self hosting.","user":{"login":"ramonsmits","id":152998,"avatar_url":"https://avatars.githubusercontent.com/u/152998?v=3","gravatar_id":"","url":"https://api.github.com/users/ramonsmits","html_url":"https://github.com/ramonsmits","followers_url":"https://api.github.com/users/ramonsmits/followers","following_url":"https://api.github.com/users/ramonsmits/following{/other_user}","gists_url":"https://api.github.com/users/ramonsmits/gists{/gist_id}","starred_url":"https://api.github.com/users/ramonsmits/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ramonsmits/subscriptions","organizations_url":"https://api.github.com/users/ramonsmits/orgs","repos_url":"https://api.github.com/users/ramonsmits/repos","events_url":"https://api.github.com/users/ramonsmits/events{/privacy}","received_events_url":"https://api.github.com/users/ramonsmits/received_events","type":"User","site_admin":false},"body":"Doco on self-hosting extended with information about configuring, initializing, creating, starting, stopping and disposing of the bus.","created_at":"2015-06-17T15:32:30Z","updated_at":"2015-06-18T13:55:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7ad35a6bb14c76aaaa68651f6027ed523e6c7d0b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Particular/docs.particular.net/pulls/675/commits","review_comments_url":"https://api.github.com/repos/Particular/docs.particular.net/pulls/675/comments","review_comment_url":"https://api.github.com/repos/Particular/docs.particular.net/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Particular/docs.particular.net/issues/675/comments","statuses_url":"https://api.github.com/repos/Particular/docs.particular.net/statuses/4b5636d9762a8254faa24394da7b810e1c8ba26b","head":{"label":"Particular:self-hosting","ref":"self-hosting","sha":"4b5636d9762a8254faa24394da7b810e1c8ba26b","user":{"login":"Particular","id":5038441,"avatar_url":"https://avatars.githubusercontent.com/u/5038441?v=3","gravatar_id":"","url":"https://api.github.com/users/Particular","html_url":"https://github.com/Particular","followers_url":"https://api.github.com/users/Particular/followers","following_url":"https://api.github.com/users/Particular/following{/other_user}","gists_url":"https://api.github.com/users/Particular/gists{/gist_id}","starred_url":"https://api.github.com/users/Particular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Particular/subscriptions","organizations_url":"https://api.github.com/users/Particular/orgs","repos_url":"https://api.github.com/users/Particular/repos","events_url":"https://api.github.com/users/Particular/events{/privacy}","received_events_url":"https://api.github.com/users/Particular/received_events","type":"Organization","site_admin":false},"repo":{"id":11727301,"name":"docs.particular.net","full_name":"Particular/docs.particular.net","owner":{"login":"Particular","id":5038441,"avatar_url":"https://avatars.githubusercontent.com/u/5038441?v=3","gravatar_id":"","url":"https://api.github.com/users/Particular","html_url":"https://github.com/Particular","followers_url":"https://api.github.com/users/Particular/followers","following_url":"https://api.github.com/users/Particular/following{/other_user}","gists_url":"https://api.github.com/users/Particular/gists{/gist_id}","starred_url":"https://api.github.com/users/Particular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Particular/subscriptions","organizations_url":"https://api.github.com/users/Particular/orgs","repos_url":"https://api.github.com/users/Particular/repos","events_url":"https://api.github.com/users/Particular/events{/privacy}","received_events_url":"https://api.github.com/users/Particular/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Particular/docs.particular.net","description":"Contains all the content for the Particular documentation site","fork":false,"url":"https://api.github.com/repos/Particular/docs.particular.net","forks_url":"https://api.github.com/repos/Particular/docs.particular.net/forks","keys_url":"https://api.github.com/repos/Particular/docs.particular.net/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Particular/docs.particular.net/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Particular/docs.particular.net/teams","hooks_url":"https://api.github.com/repos/Particular/docs.particular.net/hooks","issue_events_url":"https://api.github.com/repos/Particular/docs.particular.net/issues/events{/number}","events_url":"https://api.github.com/repos/Particular/docs.particular.net/events","assignees_url":"https://api.github.com/repos/Particular/docs.particular.net/assignees{/user}","branches_url":"https://api.github.com/repos/Particular/docs.particular.net/branches{/branch}","tags_url":"https://api.github.com/repos/Particular/docs.particular.net/tags","blobs_url":"https://api.github.com/repos/Particular/docs.particular.net/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Particular/docs.particular.net/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Particular/docs.particular.net/git/refs{/sha}","trees_url":"https://api.github.com/repos/Particular/docs.particular.net/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Particular/docs.particular.net/statuses/{sha}","languages_url":"https://api.github.com/repos/Particular/docs.particular.net/languages","stargazers_url":"https://api.github.com/repos/Particular/docs.particular.net/stargazers","contributors_url":"https://api.github.com/repos/Particular/docs.particular.net/contributors","subscribers_url":"https://api.github.com/repos/Particular/docs.particular.net/subscribers","subscription_url":"https://api.github.com/repos/Particular/docs.particular.net/subscription","commits_url":"https://api.github.com/repos/Particular/docs.particular.net/commits{/sha}","git_commits_url":"https://api.github.com/repos/Particular/docs.particular.net/git/commits{/sha}","comments_url":"https://api.github.com/repos/Particular/docs.particular.net/comments{/number}","issue_comment_url":"https://api.github.com/repos/Particular/docs.particular.net/issues/comments{/number}","contents_url":"https://api.github.com/repos/Particular/docs.particular.net/contents/{+path}","compare_url":"https://api.github.com/repos/Particular/docs.particular.net/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Particular/docs.particular.net/merges","archive_url":"https://api.github.com/repos/Particular/docs.particular.net/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Particular/docs.particular.net/downloads","issues_url":"https://api.github.com/repos/Particular/docs.particular.net/issues{/number}","pulls_url":"https://api.github.com/repos/Particular/docs.particular.net/pulls{/number}","milestones_url":"https://api.github.com/repos/Particular/docs.particular.net/milestones{/number}","notifications_url":"https://api.github.com/repos/Particular/docs.particular.net/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Particular/docs.particular.net/labels{/name}","releases_url":"https://api.github.com/repos/Particular/docs.particular.net/releases{/id}","created_at":"2013-07-28T23:18:15Z","updated_at":"2015-06-17T14:58:59Z","pushed_at":"2015-06-18T08:52:59Z","git_url":"git://github.com/Particular/docs.particular.net.git","ssh_url":"git@github.com:Particular/docs.particular.net.git","clone_url":"https://github.com/Particular/docs.particular.net.git","svn_url":"https://github.com/Particular/docs.particular.net","homepage":"http://docs.particular.net","size":31345,"stargazers_count":12,"watchers_count":12,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":67,"mirror_url":null,"open_issues_count":68,"forks":67,"open_issues":68,"watchers":12,"default_branch":"master"}},"base":{"label":"Particular:master","ref":"master","sha":"9017b6ec3c108b91ff82fff1a82725e1b8ed5e45","user":{"login":"Particular","id":5038441,"avatar_url":"https://avatars.githubusercontent.com/u/5038441?v=3","gravatar_id":"","url":"https://api.github.com/users/Particular","html_url":"https://github.com/Particular","followers_url":"https://api.github.com/users/Particular/followers","following_url":"https://api.github.com/users/Particular/following{/other_user}","gists_url":"https://api.github.com/users/Particular/gists{/gist_id}","starred_url":"https://api.github.com/users/Particular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Particular/subscriptions","organizations_url":"https://api.github.com/users/Particular/orgs","repos_url":"https://api.github.com/users/Particular/repos","events_url":"https://api.github.com/users/Particular/events{/privacy}","received_events_url":"https://api.github.com/users/Particular/received_events","type":"Organization","site_admin":false},"repo":{"id":11727301,"name":"docs.particular.net","full_name":"Particular/docs.particular.net","owner":{"login":"Particular","id":5038441,"avatar_url":"https://avatars.githubusercontent.com/u/5038441?v=3","gravatar_id":"","url":"https://api.github.com/users/Particular","html_url":"https://github.com/Particular","followers_url":"https://api.github.com/users/Particular/followers","following_url":"https://api.github.com/users/Particular/following{/other_user}","gists_url":"https://api.github.com/users/Particular/gists{/gist_id}","starred_url":"https://api.github.com/users/Particular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Particular/subscriptions","organizations_url":"https://api.github.com/users/Particular/orgs","repos_url":"https://api.github.com/users/Particular/repos","events_url":"https://api.github.com/users/Particular/events{/privacy}","received_events_url":"https://api.github.com/users/Particular/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Particular/docs.particular.net","description":"Contains all the content for the Particular documentation site","fork":false,"url":"https://api.github.com/repos/Particular/docs.particular.net","forks_url":"https://api.github.com/repos/Particular/docs.particular.net/forks","keys_url":"https://api.github.com/repos/Particular/docs.particular.net/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Particular/docs.particular.net/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Particular/docs.particular.net/teams","hooks_url":"https://api.github.com/repos/Particular/docs.particular.net/hooks","issue_events_url":"https://api.github.com/repos/Particular/docs.particular.net/issues/events{/number}","events_url":"https://api.github.com/repos/Particular/docs.particular.net/events","assignees_url":"https://api.github.com/repos/Particular/docs.particular.net/assignees{/user}","branches_url":"https://api.github.com/repos/Particular/docs.particular.net/branches{/branch}","tags_url":"https://api.github.com/repos/Particular/docs.particular.net/tags","blobs_url":"https://api.github.com/repos/Particular/docs.particular.net/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Particular/docs.particular.net/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Particular/docs.particular.net/git/refs{/sha}","trees_url":"https://api.github.com/repos/Particular/docs.particular.net/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Particular/docs.particular.net/statuses/{sha}","languages_url":"https://api.github.com/repos/Particular/docs.particular.net/languages","stargazers_url":"https://api.github.com/repos/Particular/docs.particular.net/stargazers","contributors_url":"https://api.github.com/repos/Particular/docs.particular.net/contributors","subscribers_url":"https://api.github.com/repos/Particular/docs.particular.net/subscribers","subscription_url":"https://api.github.com/repos/Particular/docs.particular.net/subscription","commits_url":"https://api.github.com/repos/Particular/docs.particular.net/commits{/sha}","git_commits_url":"https://api.github.com/repos/Particular/docs.particular.net/git/commits{/sha}","comments_url":"https://api.github.com/repos/Particular/docs.particular.net/comments{/number}","issue_comment_url":"https://api.github.com/repos/Particular/docs.particular.net/issues/comments{/number}","contents_url":"https://api.github.com/repos/Particular/docs.particular.net/contents/{+path}","compare_url":"https://api.github.com/repos/Particular/docs.particular.net/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Particular/docs.particular.net/merges","archive_url":"https://api.github.com/repos/Particular/docs.particular.net/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Particular/docs.particular.net/downloads","issues_url":"https://api.github.com/repos/Particular/docs.particular.net/issues{/number}","pulls_url":"https://api.github.com/repos/Particular/docs.particular.net/pulls{/number}","milestones_url":"https://api.github.com/repos/Particular/docs.particular.net/milestones{/number}","notifications_url":"https://api.github.com/repos/Particular/docs.particular.net/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Particular/docs.particular.net/labels{/name}","releases_url":"https://api.github.com/repos/Particular/docs.particular.net/releases{/id}","created_at":"2013-07-28T23:18:15Z","updated_at":"2015-06-17T14:58:59Z","pushed_at":"2015-06-18T08:52:59Z","git_url":"git://github.com/Particular/docs.particular.net.git","ssh_url":"git@github.com:Particular/docs.particular.net.git","clone_url":"https://github.com/Particular/docs.particular.net.git","svn_url":"https://github.com/Particular/docs.particular.net","homepage":"http://docs.particular.net","size":31345,"stargazers_count":12,"watchers_count":12,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":67,"mirror_url":null,"open_issues_count":68,"forks":67,"open_issues":68,"watchers":12,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Particular/docs.particular.net/pulls/675"},"html":{"href":"https://github.com/Particular/docs.particular.net/pull/675"},"issue":{"href":"https://api.github.com/repos/Particular/docs.particular.net/issues/675"},"comments":{"href":"https://api.github.com/repos/Particular/docs.particular.net/issues/675/comments"},"review_comments":{"href":"https://api.github.com/repos/Particular/docs.particular.net/pulls/675/comments"},"review_comment":{"href":"https://api.github.com/repos/Particular/docs.particular.net/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Particular/docs.particular.net/pulls/675/commits"},"statuses":{"href":"https://api.github.com/repos/Particular/docs.particular.net/statuses/4b5636d9762a8254faa24394da7b810e1c8ba26b"}}}}