{"id":175161,"date":"2013-04-02T18:12:03","date_gmt":"2013-04-02T14:12:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=175161"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=175161","title":{"rendered":"<span class=\"post_title\">ASP.NET MVC, WebApi, SignalR \u0438 UnityContainer<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0418\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0447\u0442\u043e \u0432\u0441\u0435 \u0445\u043e\u0440\u043e\u0448\u0438\u0435 \u0434\u0436\u0435\u0434\u0430\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 <a href=\"http:\/\/martinfowler.com\/articles\/injection.html\">\u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/a> (<a href=\"http:\/\/yugeon-dev.blogspot.ru\/2010\/07\/inversion-of-control-containers-and_21.html\">\u043f\u0435\u0440\u0435\u0432\u043e\u0434<\/a>) \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445, \u044d\u0442\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0430\u0446\u0438\u044e \u043c\u0438\u0434\u0438\u0445\u043b\u043e\u0440\u0438\u0430\u043d \u0432 \u043a\u0440\u043e\u0432\u0438 \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0430\u0441\u043f\u0435\u043a\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <a href=\"http:\/\/unity.codeplex.com\/\">UnityContainer<\/a> \u0432 ASP.NET \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0436\u0435\u043a\u0446\u0438\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432 \u0432 ASP.NET MVC \u0438 WebApi \u0438 \u0445\u0430\u0431\u043e\u0432 \u0432 SignalR. \u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442. <\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/i1.asp.net\/media\/44907\/dependency-injection-golf.png?raw=true&amp;cdn_id=2013-03-19-001\" alt=\"Dependency Injection - Golf analogy\"\/><br \/>  <a name=\"habracut\"><\/a><\/p>\n<h4>\u0422\u0435\u043e\u0440\u0438\u044f<\/h4>\n<p>  \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c <a href=\"http:\/\/msdn.microsoft.com\/ru-ru\/library\/ms172334.aspx\">\u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439<\/a> \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f:<\/p>\n<pre><code class=\"cs\">    public interface IRepository&lt;T&gt; : IDisposable {         IEnumerable&lt;string&gt; GetData();     } <\/code><\/pre>\n<p>  \u0418 \u043c\u044b \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f, \u043d\u043e \u0443\u0436\u0435 \u0441 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c. \u042f \u0432\u044b\u0431\u0440\u0430\u043b \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 EntityFramework. \u041a\u0440\u043e\u043c\u0435 \u044d\u0442\u043e\u0433\u043e, \u043e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0435 \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0438, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0430\u0445 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0442\u0438\u043f\u0430 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b.<\/p>\n<h5>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Service Locator<\/h5>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u0440\u0430\u043d\u0438\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u043e\u043b\u0435 \u0438, \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0442 \u043d\u0435\u0433\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b.<\/p>\n<pre><code class=\"cs\">    public static class Global {          public static readonly IUnityContainer ServiceLocator = new UnityContainer();     }<\/code><\/pre>\n<p>  \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0433\u0434\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u0432 Global.asax \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"cs\">Global.ServiceLocator.RegisterType(typeof(IRepository&lt;&gt;), typeof(Repository&lt;&gt;));<\/code><\/pre>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435.<\/p>\n<pre><code class=\"cs\">        public ActionResult Index() {             var repository = Global.ServiceLocator.Resolve&lt;IRepository&lt;int&gt;&gt;();             var data = repository.GetData();             return View(data);         }<\/code><\/pre>\n<p>  \u0412\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u043d\u043e, \u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 <code>Global.ServiceLocator<\/code>. \u042d\u0442\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0435 \u0442\u0430\u043a \u0441\u0442\u0440\u0430\u0448\u043d\u043e, \u043a\u0430\u043a \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u043d\u043e \u0442\u043e\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043b\u0438\u0447\u043d\u043e \u043e\u0442\u0440\u0430\u0432\u0438\u0442\u044c \u0436\u0438\u0437\u043d\u044c \u043f\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e, \u0435\u0441\u043b\u0438 \u0442\u0435\u0441\u0442\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u0430\u0445, \u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0435\u0441\u0442 \u0445\u043e\u0447\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f.<\/p>\n<h5>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Dependency Resolver<\/h5>\n<p>  ASP.NET MVC, WebApi \u0438 SignalR \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043c\u0435\u043d\u044b \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 DependencyResolvers, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439. \u041e \u0442\u043e\u043c \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.asp.net\/mvc\/tutorials\/hands-on-labs\/aspnet-mvc-4-dependency-injection\">\u041a\u0430\u043a \u044d\u0442\u043e c\u0434\u0435\u043b\u0430\u0442\u044c \u0432 ASP.NET MVC 4;<\/a><\/li>\n<li><a href=\"http:\/\/www.asp.net\/web-api\/overview\/extensibility\/using-the-web-api-dependency-resolver\">\u041a\u0430\u043a \u044d\u0442\u043e c\u0434\u0435\u043b\u0430\u0442\u044c \u0432 Web API<\/a>;<\/li>\n<li> <a href=\"http:\/\/www.kevgriffin.com\/using-unity-for-dependency-injection-with-signalr\/\">\u041a\u0430\u043a \u044d\u0442\u043e c\u0434\u0435\u043b\u0430\u0442\u044c \u0432 SignalR;<\/a><\/li>\n<\/ul>\n<p>  \u0412\u043e \u0432\u0441\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u043a\u043b\u0430\u0441\u0441, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 <code>IDependencyResolver<\/code> \u0438 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435. \u0425\u043e\u0447\u0443 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0438\u043c\u0435\u044e\u0442 \u043e\u0434\u043d\u043e \u0438\u043c\u044f, \u043d\u043e \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430\u0445 \u0438\u043c\u0451\u043d \u0438 \u0438\u043c\u0435\u044e\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u044b. \u041d\u043e \u043e\u043d\u0438 \u0438\u043c\u0435\u044e\u0442 \u043e\u0434\u043d\u0443 \u043e\u0431\u0449\u0443\u044e \u0447\u0435\u0440\u0442\u0443: \u0435\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u0440\u0435\u0448\u0451\u043d, \u0442\u043e \u043e\u043d\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 <code>null<\/code>. \u0418\u043b\u0438 \u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u043d\u0430\u0439\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u0438\u043f \u0432 <code>DefaultDependencyResolver<\/code>, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 SignalR, \u0442\u0430\u043a \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u0432 \u043d\u0451\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0432\u0441\u0435\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0435\u0433\u043e \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>IUnitiContainer.Resolve()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0431\u0440\u043e\u0441\u0438\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>  \u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0432 \u0447\u0451\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430? \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 \u043c\u0435\u0442\u043e\u0434-\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 <code>IUnityContainer.IsRegistered()<\/code> \u0438, \u0435\u0441\u043b\u0438 \u0442\u0438\u043f \u043d\u0435 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0439 <code>null<\/code>.<\/p>\n<pre><code class=\"cs\">        public static T TryResolve&lt;T&gt;(this IUnityContainer container) {             var isRegistered = true;             var typeToCheck = typeof (T);             if (typeToCheck.IsInterface || typeToCheck.IsAbstract) {                 isRegistered = container.IsRegistered(typeToCheck);                  if (!isRegistered && typeToCheck.IsGenericType) {                     var openGenericType = typeToCheck.GetGenericTypeDefinition();                     isRegistered = container.IsRegistered(openGenericType);                 }             }             return isRegistered ? container.Resolve&lt;T&gt;() : default(T);         }<\/code><\/pre>\n<p>  \u041f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u0437\u044f\u0442 \u0438\u0437 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <a href=\"http:\/\/unitymvc3.codeplex.com\/\">Unity.MVC3<\/a>. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0435\u0433\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442.<\/p>\n<blockquote><p>System.ArgumentException: The supplied type IRepository`1 does not have the same number of generic arguments as the target type Repository`1.<\/p><\/blockquote>\n<p>  \u041d\u0443 \u043b\u0430\u0434\u043d\u043e, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043b\u043e\u043a <code>try\/catch<\/code>.<\/p>\n<pre><code class=\"cs\">        public static T TryResolve&lt;T&gt;(this IUnityContainer container) {             try {                 return container.Resolve&lt;T&gt;();             }             catch (Exception) {                 return default(T);             }         }<\/code><\/pre>\n<p>  \u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0443\u0447\u0435\u0441\u0442\u044c, \u0447\u0442\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043b\u043e\u0445\u043e\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u043e\u0439, \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<blockquote><p><b>Time comparsion with 100000 iterations.<\/b>  <\/p>\n<ol>\n<li>Elapsed (Resolve when registered): 00.38940s<\/li>\n<li>Elapsed (TryResolve when registered): 00.37679s<\/li>\n<li>Elapsed (TryResolve when does&#8217;t registered): 00.00393s<\/li>\n<li>Elapsed (Resolve with IsRegistered when registered): 01.00460s<\/li>\n<li>Elapsed (Resolve with IsRegistered when does&#8217;t registered): 00.72297s<\/li>\n<li>Elapsed (Resolve with Exception when registered): 00.32938s<\/li>\n<li>Elapsed (Resolve with Exception when does&#8217;t registered): 05.60332s<\/li>\n<\/ol>\n<\/blockquote>\n<p>  \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0442\u0435\u0441\u0442\u0430 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 <code>Resolve<\/code> \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a. \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0438 \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u2014 \u043c\u0435\u0442\u043e\u0434 <code>TryResolve<\/code>, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0439\u0434\u0451\u0442 \u0440\u0430\u0437\u0433\u043e\u0432\u043e\u0440 \u043d\u0438\u0436\u0435. \u0412 \u0447\u0435\u0442\u0432\u0451\u0440\u0442\u043e\u0439 \u0438 \u043f\u044f\u0442\u043e\u0439 \u2014 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0447\u0435\u0440\u0435\u0437 <code>IsRegistered()<\/code>. \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0434\u0432\u0443\u0445 \u2014 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u043b\u043e\u043a\u0430 <code>try\/catch<\/code>. \u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432 \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u0438 \u0441\u0435\u0434\u044c\u043c\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0432 1500 \u0440\u0430\u0437. \u042d\u0442\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0437\u0430\u043c\u0435\u0442\u043d\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u043d\u043e, \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e, \u043d\u0435 \u043f\u0440\u0438\u044f\u0442\u043d\u043e.<\/p>\n<p>  \u0412 \u043d\u0435\u0434\u0440\u0430\u0445 UnityContainer \u043c\u0435\u0442\u043e\u0434 <code>TryResolve<\/code> \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a \u043f\u043e\u043b\u044e <code>UnityContainer.registeredNames.registeredKeys<\/code> \u0442\u0438\u043f\u0430 <code>Dictionary&lt;Type, List&lt;string&gt;&gt;<\/code> \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b. \u041f\u0440\u0438\u0447\u0451\u043c, \u0435\u0441\u043b\u0438 \u0442\u0438\u043f \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0431\u0435\u0437 \u0438\u043c\u0435\u043d\u0438, \u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c null \u044d\u043b\u0435\u043c\u0435\u043d\u0442. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e <code>TryResolve<\/code> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043d\u0430 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0430 \u0447\u0435\u0440\u0435\u0437 \u043a\u0443\u0447\u0443 \u043f\u043e\u0441\u0440\u0435\u0434\u043d\u0438\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0432 \u0441\u043f\u0438\u0441\u043e\u043a, \u0441\u043f\u0438\u0441\u043e\u043a \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0432\u0441\u0451 \u044d\u0442\u043e \u0432 \u0445\u0438\u0442\u0440\u044b\u0439 <code>Linq<\/code> \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0442\u0438\u043f\u0430. \u0412\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044f, \u043a\u0430\u043a \u044f \u0443\u0436\u0435 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b, \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u0432\u0438\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0441\u0438\u043b\u044c\u043d\u043e \u043d\u0435 \u0441\u043a\u0443\u0447\u0430\u043b\u0438. \u0414\u043b\u044f \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043a \u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043b\u044e, \u0447\u0442\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u043e <code>private<\/code> \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 <code>internal<\/code> \u043a\u043b\u0430\u0441\u0441\u0435. \u041d\u043e \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u0439\u0442\u0438 \u0434\u0435\u0440\u0435\u0432\u044c\u044f \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0438 \u043e\u0442\u0440\u0430\u0436\u0435\u043d\u0438\u0435.<\/p>\n<pre><code class=\"cs\">using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq.Expressions; using System.Reflection; using Microsoft.Practices.Unity;  namespace CommonInfrastructure {      public static class UnityExtensions {         private static readonly Func&lt;UnityContainer, Dictionary&lt;Type, List&lt;string&gt;&gt;&gt; GetRegisteredKeys;          private static readonly ResolverOverride[] EmptyResolverOverrides = new ResolverOverride[0];          static UnityExtensions() {             \/\/ Get information about fileds.             var unityType = typeof (UnityContainer);             var registryType = Type.GetType(&quot;Microsoft.Practices.Unity.NamedTypesRegistry, &quot; + unityType.Assembly.FullName);              const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;             var registeredNamesInfo = unityType.GetField(&quot;registeredNames&quot;, flags);             var registeredKeysInfo = registryType.GetField(&quot;registeredKeys&quot;, flags);              \/\/ Create and compile expression to accessing the field             \/\/ UnityContainer.registeredNames.registeredKeys of type Dictionary&lt;Type, List&lt;string&gt;&gt;             var unityParam = Expression.Parameter(unityType);             GetRegisteredKeys = Expression                 .Lambda&lt;Func&lt;UnityContainer, Dictionary&lt;Type, List&lt;string&gt;&gt;&gt;&gt;(                     Expression.Field(                         Expression.Field(                             unityParam,                             registeredNamesInfo),                         registeredKeysInfo),                     unityParam)                 .Compile();         }     .... <\/code><\/pre>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u0438\u043f\u044b \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u0438 <code>internal<\/code> \u043a\u043b\u0430\u0441\u0441\u0430 <code>NamedTypesRegistry<\/code>, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0432 \u0442\u043e\u0439 \u0436\u0435 \u0441\u0431\u043e\u0440\u043a\u0435. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <code>FieldInfo<\/code> \u0434\u043b\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439. \u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432\u0438\u0434\u0430 <code>Func&lt;UnityContainer, Dictionary&lt;Type, List&lt;string&gt;&gt;&gt; GetRegisteredKeys = container =&gt; container.registeredNames.registeredKeys;<\/code>.<\/p>\n<pre><code class=\"cs\">    ....          \/\/\/ &lt;summary&gt;         \/\/\/     Try to resolve an instance of requested type &lt;typeparamref name=&quot;T&quot; \/&gt; without name.         \/\/\/     If type is interface or abstract class and it is't registered then return null.         \/\/\/ &lt;\/summary&gt;         public static T TryResolve&lt;T&gt;(this IUnityContainer container) where T : class {             return (T) TryResolve(container, typeof (T));         }          \/\/\/ &lt;summary&gt;         \/\/\/     Try to resolve an instance of requested &lt;paramref name=&quot;type&quot; \/&gt; without name.         \/\/\/     If type is interface or abstract class and it is't registered then return null.         \/\/\/ &lt;\/summary&gt;         public static object TryResolve(this IUnityContainer container, Type type) {             bool resolve;             if (type.IsInterface || type.IsAbstract) {                 \/\/ Get the dictionary with registered types and names.                 var keys = GetRegisteredKeys((UnityContainer) container);                  \/\/ Check if interface or abstract type is registered in the container.                 resolve = IsRegistered(type, keys);                  \/\/ If type still is't registered and it's generic type then check if generic type definition is registered.                 if (!resolve && type.IsGenericType) {                     var openGenericType = type.GetGenericTypeDefinition();                     resolve = IsRegistered(openGenericType, keys);                 }             }             else {                 \/\/ If type can be created then resolve it immediately.                 resolve = true;             }              \/\/ If type is registered then resolve it or return null if nothing was found.             return resolve ? container.Resolve(type, null, EmptyResolverOverrides) : null;         }          private static bool IsRegistered(Type type, Dictionary&lt;Type, List&lt;string&gt;&gt; keys) {             List&lt;string&gt; names;             if (keys.TryGetValue(type, out names)) {                 \/\/ By default type without name is registered with null string.                 if (names.Exists(name =&gt; ReferenceEquals(name, null))) {                     return true;                 }             }             return false;         }     } }<\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0442\u0438\u043f \u043d\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0435\u0441\u0442\u044c \u043b\u0438 \u0432 \u043d\u0451\u043c \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c \u0442\u0438\u043f \u0441 \u043f\u0443\u0441\u0442\u044b\u043c \u0438\u043c\u0435\u043d\u0435\u043c. \u0415\u0441\u043b\u0438 \u0442\u0438\u043f \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c, \u0438\u043b\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c, \u0442\u043e \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0435\u0433\u043e \u0441\u0440\u0430\u0437\u0443 \u0436\u0435.<\/p>\n<p>  \u041c\u043e\u0436\u043d\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0434\u043b\u044f UnityContainer \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0433\u043e \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435: <a href=\"http:\/\/blogs.msdn.com\/b\/erwinvandervalk\/archive\/2009\/02\/13\/test-if-classes-are-registered-in-unity.aspx\">Test if classes are registered in unity<\/a>. \u041d\u043e, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438.<\/p>\n<h5>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0430\u043a\u0442\u0438\u0432\u0430\u0442\u043e\u0440\u043e\u0432<\/h5>\n<p>  ASP.NET MVC, WebApi \u0438 SignalR \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432 \u0438 \u0445\u0430\u0431\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 <code>I*Activator<\/code>. \u0412 ASP.NET MVC \u044d\u0442\u043e <code>System.Web.Mvc.IControllerActivator<\/code>, \u0432 WebApi \u044d\u0442\u043e <code>System.Web.Http.Dispatcher.IHttpControllerActivator<\/code>, \u0432 SignalR \u044d\u0442\u043e <code>Microsoft.AspNet.SignalR.Hubs.IHubActivator<\/code>. \u0412\u0441\u0435 \u043e\u043d\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>Create<\/code>, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u0438\u043f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435. \u041e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u0438 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u0445.<\/p>\n<p>  <b>ASP.NET MVC<\/b>  <\/p>\n<pre><code class=\"cs\">using System; using System.Diagnostics; using System.Web.Mvc; using System.Web.Routing; using Microsoft.Practices.Unity;  namespace WebApp.Infrastructure {     public sealed class UnityControllerActivator : IControllerActivator {         private readonly IUnityContainer _container;          public UnityControllerActivator(IUnityContainer container) {             _container = container;         }          public IController Create(RequestContext requestContext, Type controllerType) {             return (IController) _container.Resolve(controllerType);         }     } }<\/code><\/pre>\n<p>  <b>WebApi<\/b>  <\/p>\n<pre><code class=\"cs\">using System; using System.Diagnostics; using System.Net.Http; using System.Web.Http.Controllers; using System.Web.Http.Dispatcher; using Microsoft.Practices.Unity;  namespace WebApp.Infrastructure {     public sealed class UnityHttpControllerActivator : IHttpControllerActivator {         private readonly IUnityContainer _container;          public UnityHttpControllerActivator(IUnityContainer container) {             _container = container;         }          public IHttpController Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType) {             return (IHttpController) _container.Resolve(controllerType);         }     } }<\/code><\/pre>\n<p>  <b>SignalR<\/b>  <\/p>\n<pre><code class=\"cs\">using System.Diagnostics; using Microsoft.AspNet.SignalR.Hubs; using Microsoft.Practices.Unity;  namespace WebApp.Infrastructure {     public sealed class UnityHubActivator : IHubActivator {         private readonly IUnityContainer _container;          public UnityHubActivator(IUnityContainer container) {             Debug.Assert(container != null, &quot;container == null&quot;);              _container = container;         }          public IHub Create(HubDescriptor descriptor) {             var hubType = descriptor.HubType;             return hubType != null ? _container.Resolve(hubType) as IHub : null;         }     } }<\/code><\/pre>\n<p>  \u0417\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u0430\u043a\u0442\u0438\u0432\u0430\u0442\u043e\u0440\u044b \u0432 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435.<\/p>\n<pre><code class=\"cs\">using System.Web.Http; using System.Web.Http.Dispatcher; using System.Web.Mvc; using Microsoft.AspNet.SignalR; using Microsoft.AspNet.SignalR.Hubs; using Microsoft.Practices.Unity; using WebApp.Infrastructure; using WebApp.Models;  namespace WebApp.App_Start {     public static class ContainerConfig {         public static void Config() {             var container = new UnityContainer();             MapTypes(container);              \/\/ Set resolver to MVC.             var controllerActivator = new UnityControllerActivator(container);             ControllerBuilder.Current.SetControllerFactory(new DefaultControllerFactory(controllerActivator));              \/\/ Set resolver to WebApi.             var httpControllerActivator = new UnityHttpControllerActivator(container);             GlobalConfiguration.Configuration.Services.Replace(typeof (IHttpControllerActivator), httpControllerActivator);              \/\/ Set resolver to SignalR.             var hubActivator = new UnityHubActivator(container);             GlobalHost.DependencyResolver.Register(typeof (IHubActivator), () =&gt; hubActivator);         }          private static void MapTypes(IUnityContainer container) {             container.RegisterType(typeof(IRepository&lt;&gt;), typeof(Repository&lt;&gt;));         }     } }<\/code><\/pre>\n<p>  \u0418 \u0432\u044b\u0437\u043e\u0432\u0435\u043c \u0432\u0441\u0451 \u044d\u0442\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0432 <code>Global.asax<\/code>. \u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u043c, \u0447\u0442\u043e SignalR \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u043f\u0435\u0440\u0435\u0434 \u0432\u0441\u0435\u043c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c.<\/p>\n<pre><code class=\"cs\">using System.Web; using System.Web.Http; using System.Web.Mvc; using System.Web.Optimization; using System.Web.Routing; using WebApp.App_Start;  namespace WebApp {     public class MvcApplication : HttpApplication {         protected void Application_Start() {             ContainerConfig.Config();              SignalRConfig.Config(RouteTable.Routes);              AreaRegistration.RegisterAllAreas();             WebApiConfig.Config(GlobalConfiguration.Configuration);             FilterConfig.Config(GlobalFilters.Filters);             RouteConfig.Config(RouteTable.Routes);             BundleConfig.Config(BundleTable.Bundles);             AuthConfig.Config();         }     } }<\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432 \u0438 \u0445\u0430\u0431\u043e\u0432. <\/p>\n<h4>\u041f\u0440\u0430\u043a\u0442\u0438\u043a\u0430<\/h4>\n<p>  \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043e\u0434\u043d\u043e\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438\u0437 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043f\u0443\u0442\u044f\u043c\u0438. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439, \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 <code>GetData()<\/code> \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u043e\u0437\u043d\u0430\u0442\u044c, \u0438\u0437 \u043a\u0430\u043a\u043e\u0433\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u043e\u043d\u0438 \u0431\u044b\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u044b. \u0422\u0430\u043a\u0436\u0435, \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d \u043f\u043e\u0441\u043b\u0435 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430. <\/p>\n<pre><code class=\"cs\">    public sealed class Repository&lt;T&gt; : IRepository&lt;T&gt; {         public IEnumerable&lt;string&gt; GetData() {             for (int i = 0; i &lt; 10; i++) {                 yield return string.Format(&quot;Data {0} of type {1}&quot;, i, typeof (T));             }         }          public void Dispose() {             Debug.WriteLine(&quot;Repository&lt;{0}&gt;.Dispose&quot;, typeof (T));         }     }<\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u0434\u043b\u044f ASP.NET MVC \u0438 WebApi \u0438 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043c \u0438\u0445 \u0432 \u043f\u0430\u043f\u043a\u0443 Controllers, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043d\u0430\u0440\u0443\u0448\u0430\u0442\u044c \u043a\u043e\u043d\u0432\u0435\u043d\u0446\u0438\u0438. \u0425\u043e\u0447\u0443 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043a \u043a\u043b\u0430\u0441\u0441\u0430\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u044b \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b <code>System.Web.Mvc.AuthorizeAttribute<\/code> \u0438 <code>System.Web.Http.AuthorizeAttribute<\/code> \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043d\u0435\u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c. \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u043e\u0441\u044c \u043d\u0430 \u0431\u0430\u0437\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 ASP.NET MVC 4 Web Application \u2014 Single Page Application, \u0442\u0430\u043a \u0447\u0442\u043e \u0432\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430\u044f \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430\u044f \u0434\u043b\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0440\u043e\u043b\u0435\u0439 \u0442\u0430\u043c \u0443\u0436\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442.<\/p>\n<p>  <b>ASP.NET MVC<\/b>  <\/p>\n<pre><code class=\"cs\">using System.Web.Mvc; using WebApp.Models;  namespace WebApp.Controllers {      [Authorize]     public sealed class DataController : Controller {         private readonly IRepository&lt;int&gt; _repository;          public DataController(IRepository&lt;int&gt; repository) {             _repository = repository;         }          \/\/ GET: \/Data\/         public ActionResult Index() {             ViewBag.Title = &quot;Data from DataController&quot;;             var data = _repository.GetData();             return View(data);         }          protected override void Dispose(bool disposing) {             _repository.Dispose();             base.Dispose(disposing);         }     } }<\/code><\/pre>\n<p>  <b>WebApi<\/b>  <\/p>\n<pre><code class=\"cs\">using System.Collections.Generic; using System.Web.Http; using WebApp.Filters; using WebApp.Models;  namespace WebApp.Controllers {      [Authorize]     [ValidateHttpAntiForgeryToken]     public sealed class DataWebApiController : ApiController {         private readonly IRepository&lt;string&gt; _repository;          public DataWebApiController(IRepository&lt;string&gt; repository) {             _repository = repository;         }          \/\/ GET \/api\/DataWebApi\/         public IEnumerable&lt;string&gt; GetData() {             return _repository.GetData();         }          protected override void Dispose(bool disposing) {             _repository.Dispose();             base.Dispose(disposing);         }     } }<\/code><\/pre>\n<p>  \u0412 \u043f\u0430\u043f\u043a\u0435 Hubs \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0445\u0430\u0431 \u0441 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e. \u0415\u0433\u043e \u0442\u043e\u0436\u0435 \u043f\u043e\u043c\u0435\u0442\u0438\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u043c <code>Microsoft.AspNet.SignalR.AuthorizeAttribute<\/code>.<\/p>\n<p>  <b>SignalR<\/b>  <\/p>\n<pre><code class=\"cs\">using System.Collections.Generic; using Microsoft.AspNet.SignalR; using WebApp.Models;  namespace WebApp.Hubs {      [Authorize]     public sealed class DataHub : Hub {         private readonly IRepository&lt;double&gt; _repository;          public DataHub(IRepository&lt;double&gt; repository) {             _repository = repository;         }          public IEnumerable&lt;string&gt; GetData() {             return _repository.GetData();         }          protected override void Dispose(bool disposing) {             _repository.Dispose();             base.Dispose(disposing);         }     } }<\/code><\/pre>\n<p>  \u0412\u043e \u0432\u0441\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440. \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0430\u043a\u0442\u0438\u0432\u0430\u0442\u043e\u0440\u044b, \u0442\u043e \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0445\u0430\u0431\u0430 \u0438\u043b\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0438\u043f \u043e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f.<\/p>\n<p>  \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 TypeScript. \u0414\u043b\u044f \u0435\u0433\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u043f\u043b\u0430\u0433\u0438\u043d <a href=\"http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=34790\">TypeScript for Visual Studio 2012<\/a>, \u0430 \u0442\u0430\u043a\u0436\u0435 <a href=\"http:\/\/vswebessentials.com\/\">Web Essentials 2012<\/a>. \u0412\u0441\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u044b, \u043e\u0442\u043d\u043e\u0441\u044f\u0449\u0438\u0435\u0441\u044f \u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e, \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043f\u0430\u043f\u043a\u0435 <code>Scripts\/app<\/code>. \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 NuGet \u043f\u0430\u043a\u0435\u0442\u044b: <a href=\"http:\/\/twitter.github.com\/bootstrap\/\">Twitter.Bootstrap<\/a>, <a href=\"http:\/\/requirejs.org\/\">RequireJs<\/a>, <a href=\"http:\/\/knockoutjs.com\/index.html\">KnockoutJs<\/a>, <a href=\"http:\/\/jquery.com\/\">jQuery<\/a>, <a href=\"https:\/\/github.com\/SignalR\">SignalR<\/a>, \u0430 \u0442\u0430\u043a\u0436\u0435 <a href=\"http:\/\/nuget.org\/packages?q=TypeScript.DefinitelyTyped\">TypeScript Definitions<\/a> \u0434\u043b\u044f \u043d\u0438\u0445. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f TypeScript. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0441\u0442\u043e\u0438\u0442 ReSharper, \u0442\u043e \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0434\u043b\u043e \u0441\u043a\u0440\u044b\u0442\u044c \u043f\u0443\u043d\u043a\u0442\u044b \u043c\u0435\u043d\u044e \u0441 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430\u043c\u0438 \u0434\u043b\u044f TypeScript, \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e, \u0441\u043d\u0438\u043c\u0435\u043c \u0433\u0430\u043b\u043a\u0443 \u0441 \u043f\u0443\u043d\u043a\u0442\u0430 \u00abHide overridden Visual Studio menu items\u00bb \u0432 \u0435\u0433\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0435\u0451 \u0432 AMD \u0444\u043e\u0440\u043c\u0430\u0442\u0435.<\/p>\n<p>  <b>\/scripts\/app\/app.ts<\/b>  <\/p>\n<pre><code>\/\/\/ &lt;reference path=&quot;..\/typings\/knockout\/knockout.d.ts&quot; \/&gt; \/\/\/ &lt;reference path=&quot;..\/typings\/jquery\/jquery.d.ts&quot; \/&gt; \/\/\/ &lt;reference path=&quot;..\/typings\/signalr\/signalr.d.ts&quot; \/&gt;  \/**  * Helper method to creating ajax requests with anti firgery token. * @param type Request type: get, post, delete, put. * @param url A string containing the URL to which the request is sent. * @param data Data to be sent to the server. Before sending serializes to Json format. * @param dataType The type of data that you're expecting back from the server. Default is Json. *\/ function ajaxRequest(type: string, url: string, data?: any, dataType: string = &quot;json&quot;) {     var headers = {};     var antiForgeryToken = $(&quot;#antiForgeryToken&quot;).val();     if (antiForgeryToken) {         headers = {             'RequestVerificationToken': antiForgeryToken         }     }     return $.ajax(url, {         headers: headers,         dataType: dataType,         contentType: &quot;application\/json&quot;,         cache: false,         type: type,         data: data ? data.toJson() : null     }); }  interface IDataHub {     client: {};     server: {         getData(): JQueryDeferred;     }; }  export class AppViewModel {     private dataHub: IDataHub;      \/** If error occurred this field should contain error message. Otherwise it's empty string. *\/     errorMessage = ko.observable(&quot;&quot;);      \/** Displays optional text. *\/     text = ko.observable(&quot;&quot;);      \/** Data received from server. *\/     data = ko.observableArray([]);      \/** Create ViewModel and connect to hubs. *\/     constructor() {         this.dataHub = $.connection[&quot;dataHub&quot;];         $.connection.hub             .start()             .fail(e =&gt; this.onFail(e));     }      \/** Receive data from SignalR hub. *\/     signalrBtnClick() {         this.text(&quot;SignalR&quot;);         this.dataHub.server             .getData()             .done(d =&gt; this.showData(d))             .fail(e =&gt; this.onFail(e));     }      \/** Receive data from WebApi controller. *\/     apiBtnClick() {         this.text(&quot;WebApi&quot;);         ajaxRequest(&quot;get&quot;, &quot;\/api\/dataWebApi&quot;)             .done(d =&gt; this.showData(d))             .fail(e =&gt; this.onFail(e));     }      \/** Receive data from static page controller. *\/     staticBtnClick() {         ajaxRequest(&quot;get&quot;, &quot;\/Data&quot;, null, &quot;html&quot;)             .done(data =&gt; {                 this.data([]);                 this.errorMessage(&quot;&quot;);                 this.text(data);             })             .fail(e =&gt; this.onFail(e));     }      private onFail(error: string) {         this.text(&quot;Error!&quot;);         this.data([]);         this.errorMessage(error);     }      private showData(data: string[]) {         this.data(data);         this.errorMessage(&quot;&quot;);     } }<\/code><\/pre>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0435\u0451 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f, \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0445\u0430\u0431\u043e\u043c <code>DataHub<\/code>. \u0414\u0430\u043b\u0435\u0435, \u0432 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 <code>*BtnClick<\/code>, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u0438\u0432\u044f\u0437\u043e\u043a.<\/p>\n<pre><code class=\"html\">&lt;div class=&quot;row&quot;&gt;     &lt;div class=&quot;span2&quot;&gt;         &lt;div class=&quot;btn-group btn-group-vertical&quot; data-toggle=&quot;buttons-radio&quot;&gt;             &lt;button class=&quot;btn span2&quot; data-bind=&quot;click: signalrBtnClick&quot;&gt;SignalR&lt;\/button&gt;             &lt;button class=&quot;btn span2&quot; data-bind=&quot;click: apiBtnClick&quot;&gt;WebApi&lt;\/button&gt;             &lt;button class=&quot;btn span2&quot; data-bind=&quot;click: staticBtnClick&quot;&gt;Static page&lt;\/button&gt;         &lt;\/div&gt;     &lt;\/div&gt;      &lt;div class=&quot;span5&quot;&gt;         &lt;div  data-bind=&quot;visible: errorMessage() != ''&quot;&gt;             &lt;span class=&quot;text-error&quot; data-bind=&quot;text: errorMessage&quot;&gt;&lt;\/span&gt;         &lt;\/div&gt;          &lt;div  class=&quot;well&quot; data-bind=&quot;visible: text() != ''&quot;&gt;             &lt;p data-bind=&quot;html: text&quot;&gt;&lt;\/p&gt;             &lt;ol data-bind=&quot;foreach: data&quot;&gt;                 &lt;li&gt;&lt;span data-bind=&quot;text: $data&quot;&gt;&lt;\/span&gt;&lt;\/li&gt;             &lt;\/ol&gt;         &lt;\/div&gt;     &lt;\/div&gt; &lt;\/div&gt;<\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0431\u0440\u0430, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0433\u0434\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u044b, \u043a\u0440\u043e\u043c\u0435 <code>require.js<\/code> \u0438 \u0444\u0430\u0439\u043b\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f. \u0414\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0445\u0430\u0431\u0430\u043c \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442 <code>~\/signalr\/hubs<\/code>. \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u0438\u043d\u0434\u0438\u043d\u0433\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u0444\u0430\u0439\u043b\u0435 <code>init.ts<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d RequireJs \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438. \u0414\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u043d\u0430 \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u0435\u043c RequireJs \u043f\u0435\u0440\u0435\u0434 \u0435\u0433\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439.<\/p>\n<pre><code>&lt;script src=&quot;~\/signalr\/hubs&quot;&gt; &lt;\/script&gt;        &lt;script type=&quot;text\/javascript&quot;&gt; var require = {     waitSeconds: 15,     urlArgs: &quot;bust=&quot; + new Date().getTime() }; &lt;\/script&gt; &lt;script data-main=&quot;\/scripts\/app\/init&quot; type=&quot;text\/javascript&quot; src=&quot;@Scripts.Url(&quot;~\/Scripts\/require.js&quot;)&quot;&gt; &lt;\/script&gt;<\/code><\/pre>\n<p>  \u0412 <code>init.ts<\/code> \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043c\u043e\u0434\u0443\u043b\u044c \u0441 \u043c\u043e\u0434\u0435\u043b\u044c\u044e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438. \u0414\u043b\u044f \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u0438 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0430 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0432 TypeScript \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u00abUse the AMD module\u00bb \u0432 true \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445 \u00abTools\u00bb-\u00abOptions\u00bb-\u00abWeb Essentials\u00bb-\u00abTypeScript\u00bb-\u00abCompiler flags\u00bb.<\/p>\n<p>  <b>\/scripts\/app\/init.ts<\/b>  <\/p>\n<pre><code>import app = module(&quot;app&quot;); $(() =&gt; {     ko.applyBindings(new app.AppViewModel()); });<\/code><\/pre>\n<p>  \u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <code>export<\/code> \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u0442 \u043a\u043b\u0430\u0441\u0441, \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043a\u0430\u043a \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c\u0443\u044e. \u0418\u043c\u043f\u043e\u0440\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432 <code>import <\/code>\u0438 <code>module <\/code>, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0447\u043b\u0435\u043d\u0430\u043c \u0432 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435. \u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043d\u0435\u0447\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u044d\u0442\u043e\u0433\u043e.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/d62\/880\/33b\/d6288033bb839f884b10887f28c464e8.png\"\/><\/p>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u041a\u0430\u043a \u0431\u044b\u043b\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u044b\u0448\u0435, \u0435\u0434\u0438\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0432 ASP.NET \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438 \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0441\u043e\u0431\u044b\u0445 \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0435\u0439. \u042d\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e \u0432 \u043e\u0434\u043d\u043e\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445, \u0433\u0434\u0435 \u0438\u043d\u043e\u0433\u0434\u0430 \u0431\u044b\u0432\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0446\u0435\u043b\u0435\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438, \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0434\u043b\u044f \u043d\u0438\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0435. TypeScript \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0441\u0435\u0431\u044f \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 \u0441\u0432\u0435\u0442\u0435 \u043d\u0435\u0434\u0430\u0432\u043d\u0435\u0433\u043e \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0432 NuGet \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u0441 TypeScript Definitions. \u041a\u0430\u0442\u0430\u043b\u043e\u0433 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u043e\u0432, \u043f\u0440\u0430\u0432\u0434\u0430, \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u043e JetBrains <a href=\"http:\/\/blogs.jetbrains.com\/dotnet\/2013\/03\/introducing-the-resharper-8-eap\/\">\u043e\u0431\u0435\u0449\u0430\u044e\u0442<\/a> \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 TypeScript \u0443\u0436\u0435 \u0432 ReSharper \u0443\u0436\u0435 \u0432 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u043c \u0431\u0443\u0434\u0443\u0449\u0435\u043c. SignalR \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0443\u0442\u043e\u0439 \u0448\u0442\u0443\u043a\u043e\u0439. \u0423\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0442\u043e, \u0447\u0442\u043e WebSockets \u043e\u0442\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u043e\u0434 Windows7, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u0435\u0437\u0434\u0435 \u0438 \u0441\u0430\u043c\u0430 \u0432\u044b\u0431\u0438\u0440\u0435\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043c\u043e\u0436\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u043c\u043e\u0447\u044c \u043f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435.    \t \t\t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/175161\/\"> http:\/\/habrahabr.ru\/post\/175161\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0418\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0447\u0442\u043e \u0432\u0441\u0435 \u0445\u043e\u0440\u043e\u0448\u0438\u0435 \u0434\u0436\u0435\u0434\u0430\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 <a href=\"http:\/\/martinfowler.com\/articles\/injection.html\">\u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/a> (<a href=\"http:\/\/yugeon-dev.blogspot.ru\/2010\/07\/inversion-of-control-containers-and_21.html\">\u043f\u0435\u0440\u0435\u0432\u043e\u0434<\/a>) \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445, \u044d\u0442\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0430\u0446\u0438\u044e \u043c\u0438\u0434\u0438\u0445\u043b\u043e\u0440\u0438\u0430\u043d \u0432 \u043a\u0440\u043e\u0432\u0438 \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0430\u0441\u043f\u0435\u043a\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <a href=\"http:\/\/unity.codeplex.com\/\">UnityContainer<\/a> \u0432 ASP.NET \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0436\u0435\u043a\u0446\u0438\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432 \u0432 ASP.NET MVC \u0438 WebApi \u0438 \u0445\u0430\u0431\u043e\u0432 \u0432 SignalR. \u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442. <\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/i1.asp.net\/media\/44907\/dependency-injection-golf.png?raw=true&amp;cdn_id=2013-03-19-001\" alt=\"Dependency Injection - Golf analogy\"\/>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-175161","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/175161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=175161"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/175161\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=175161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=175161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=175161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}