{"id":280263,"date":"2016-11-01T11:10:11","date_gmt":"2016-11-01T08:10:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=280263"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=280263","title":{"rendered":"Repository Pattern via CSLA .NET"},"content":{"rendered":"<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c \u0441 \u043d\u0438\u0437\u043a\u043e\u0439 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0441\u0442\u044c\u044e (Low Coupling) \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432 \u043f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u041f\u041e. \u0412 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043a\u0430\u0440\u043a\u0430\u0441\u0430 <a href=\"http:\/\/cslanet.com\/\">CSLA .NET<\/a>, \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u044b\u0432\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e.<\/p>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043e\u0442\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c (Data Access Layer, DAL) \u043e\u0442 \u0441\u043b\u043e\u044f \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0438 (Business Layer) \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/ff649690.aspx\">\u0448\u0430\u0431\u043b\u043e\u043d\u0430 Repository<\/a> \u0438 \u043e\u043f\u0438\u0441\u0430\u043d \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 (Depency Injection) \u0432 \u0431\u0438\u0437\u043d\u0435\u0441-\u043e\u0431\u044a\u0435\u043a\u0442\u044b CSLA .NET. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f CSLA \u0432\u0435\u0440\u0441\u0438\u0438 4.1.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>\u041f\u0440\u0438\u043c\u0435\u0440<\/h2>\n<p>  \u0418\u0442\u0430\u043a, \u043f\u0443\u0441\u0442\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u0431\u0438\u0437\u043d\u0435\u0441-\u043e\u0431\u044a\u0435\u043a\u0442 Person. \u0423 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0431\u0438\u0437\u043d\u0435\u0441-\u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0438\u0437 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438, \u0434\u043e\u0447\u0435\u0440\u043d\u044f\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 Orders \u0438 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 Address:<\/p>\n<pre><code>\/\/Person.cs [Serializable] public sealed partial class Person : BusinessBase&lt;Person&gt; {    private Person( ) { }     public static Person NewPerson( ) {       return DataPortal.Create&lt;Person&gt;( );    }     public static Person GetPerson( int personId ) {       return DataPortal.Fetch&lt;Person&gt;( new SingleCriteria&lt;Person, int&gt;( personId ) );    }     public static void RemovePerson( int personId ) {       DataPortal.Delete&lt;Person&gt;( new SingleCriteria&lt;Person, int&gt;( personId ) );    }     private static readonly PropertyInfo&lt;int&gt; IdProperty = RegisterProperty&lt;int&gt;( c =&gt; c.Id );     public int Id {       get { return GetProperty( IdProperty ); }       private set { LoadProperty( IdProperty, value ); }    }     public static readonly PropertyInfo&lt;string&gt; FirstNameProperty =             RegisterProperty&lt;string&gt;( c =&gt; c.FirstName );     public string FirstName {       get { return GetProperty( FirstNameProperty ); }       set { SetProperty( FirstNameProperty, value ); }    }     public static readonly PropertyInfo&lt;string&gt; SecondNameProperty =             RegisterProperty&lt;string&gt;( c =&gt; c.SecondName );     public string SecondName {       get { return GetProperty( SecondNameProperty ); }       set { SetProperty( SecondNameProperty, value ); }    }     public static readonly PropertyInfo&lt;int&gt; AgeProperty = RegisterProperty&lt;int&gt;( c =&gt; c.Age );     public int Age {       get { return GetProperty( AgeProperty ); }       set { SetProperty( AgeProperty, value ); }    }     public static readonly PropertyInfo&lt;string&gt; CommentProperty =             RegisterProperty&lt;string&gt;( c =&gt; c.Comment );     public string Comment {       get { return GetProperty( CommentProperty ); }       set { SetProperty( CommentProperty, value ); }    }     public static readonly PropertyInfo&lt;Orders&gt; OrdersProperty =             RegisterProperty&lt;Orders&gt;( c =&gt; c.Orders,                        RelationshipTypes.Child | RelationshipTypes.LazyLoad );     public Orders Orders {       get {          if ( !FieldManager.FieldExists( OrdersProperty ) ) {             Orders = Orders.NewOrders( );          }          return GetProperty( OrdersProperty );       }       private set {          LoadProperty( OrdersProperty, value );          OnPropertyChanged( OrdersProperty );       }    }     public static readonly PropertyInfo&lt;Address&gt; AddressProperty =             RegisterProperty&lt;Address&gt;( c =&gt; c.Address,                        RelationshipTypes.Child | RelationshipTypes.LazyLoad);     public Address Address {       get {          if ( !FieldManager.FieldExists( AddressProperty ) ) {             Address = Address.NewAddress( );          }          return GetProperty( AddressProperty );       }       private set {          LoadProperty( AddressProperty, value );          OnPropertyChanged( AddressProperty );       }    } } <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>\/\/Orders.cs     [Serializable] public sealed partial class Orders : BusinessListBase&lt;Orders, Order&gt; {    private Orders( ) { }     public static Orders NewOrders( ) {       return DataPortal.CreateChild&lt;Orders&gt;( );    } }  \/\/Order.cs [Serializable] public sealed partial class Order : BusinessBase&lt;Order&gt; {    private Order( ) { }     public static Order NewOrder( ) {       return DataPortal.CreateChild&lt;Order&gt;( );    }     public static readonly PropertyInfo&lt;int&gt; IdProperty = RegisterProperty&lt;int&gt;( c =&gt; c.Id );     public int Id {       get { return GetProperty( IdProperty ); }       set { LoadProperty( IdProperty, value ); }    }     public static readonly PropertyInfo&lt;string&gt; DescriptionProperty =             RegisterProperty&lt;string&gt;( c =&gt; c.Description );     public string Description {       get { return GetProperty( DescriptionProperty ); }       set { SetProperty( DescriptionProperty, value ); }    } }  \/\/Address.cs [Serializable] public partial class Address : BusinessBase&lt;Address&gt; {    private Address( ) { }     public static Address NewAddress( ) {       return DataPortal.CreateChild&lt;Address&gt;( );    }     private static readonly PropertyInfo&lt;int&gt; IdProperty = RegisterProperty&lt;int&gt;( c =&gt; c.Id );     private int Id {       get { return GetProperty( IdProperty ); }       set { LoadProperty( IdProperty, value ); }    }     public static readonly PropertyInfo&lt;string&gt; FirstAddressProperty =             RegisterProperty&lt;string&gt;( c =&gt; c.FirstAddress );     public string FirstAddress {       get { return GetProperty( FirstAddressProperty ); }       set { SetProperty( FirstAddressProperty, value ); }    }     public static readonly PropertyInfo&lt;string&gt; SecondAddressProperty =             RegisterProperty&lt;string&gt;( c =&gt; c.SecondAddress );     public string SecondAddress {       get { return GetProperty( SecondAddressProperty ); }       set { SetProperty( SecondAddressProperty, value ); }    } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0430\u044f\u0441\u044f \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435: <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/10d\/cd7\/528\/10dcd75289e244f5b4d7a08a560c4e5d.png\"\/><\/p>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0431\u0438\u0437\u043d\u0435\u0441-\u043a\u043b\u0430\u0441\u0441\u044b \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u044b \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c partial, \u0438 \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0435\u043d \u0432 \u0434\u0440\u0443\u0433\u0438\u0435 \u0447\u0430\u0441\u0442\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u043e\u0434 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a DAL.<\/p>\n<h2>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 DAL<\/h2>\n<p>  \u0421\u043f\u0435\u0440\u0432\u0430 \u043e\u0431\u0440\u0430\u0442\u0438\u043c\u0441\u044f \u043a \u043a\u043e\u0434\u0443, \u043e\u0442\u043d\u043e\u0441\u044f\u0449\u0435\u043c\u0443\u0441\u044f \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Person. \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u0443 \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0417\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0442 \u0444\u0430\u0431\u0440\u0438\u0447\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u043a \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u043c\u0443 \u043f\u043e\u0440\u0442\u0430\u043b\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 CSLA. \u041a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0439 \u043f\u043e\u0440\u0442\u0430\u043b \u0434\u0430\u043d\u043d\u044b\u0445, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u043c\u0443 \u043f\u043e\u0440\u0442\u0430\u043b\u0443 \u0434\u0430\u043d\u043d\u044b\u0445. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u044e \u043a \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c DataPortal_Create \u0438\u043b\u0438 DataPortal_Fetch \u043a\u043b\u0430\u0441\u0441\u0430 Person \u2013 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438\u043b\u0438 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/47d\/9a1\/6ef\/47d9a16effea44b99a9443855a4088d8.png\"\/><br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/6d7\/b67\/237\/6d7b67237d094518ab69d7d6c1073c0c.png\"\/><\/p>\n<p>  \u0414\u043b\u044f \u0432\u0441\u0442\u0430\u0432\u043a\u0438, \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Person \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0430 \u0436\u0435 \u0441\u0445\u0435\u043c\u0430, \u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u044b DataPortal_Insert, DataPortal_Update \u0438 DataPortal_DeleteSelf \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/688\/b8d\/66b\/688b8d66baf94201be61c64e64ba6df6.png\"\/><\/p>\n<p>  \u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434 Save (\u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 CSLA) \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u043e\u0432\u044b\u0439 \u0431\u0438\u0437\u043d\u0435\u0441-\u043e\u0431\u044a\u0435\u043a\u0442, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u043c \u043f\u043e\u0440\u0442\u0430\u043b\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0432\u0441\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u043c \u043a\u043e\u0434\u0435 (\u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f \u0442.\u043d. \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0445 \u0431\u0438\u0437\u043d\u0435\u0441-\u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, Mobile Object Pattern):<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/34d\/51e\/4b9\/34d51e4b91b2469eb631029881591f17.png\"\/><\/p>\n<p>  \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0434\u043b\u044f \u0444\u043e\u0440\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 DataPortal_Delete:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/006\/ca4\/4ce\/006ca44ceaba493fa9320e2ed96f02ca.png\"\/><\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 DataPortal_XYZ \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0441\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u2013 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u043e \u0438 \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Person \u0432 DAL. \u0412 \u044d\u0442\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c: \u043a\u043e\u0434 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438 \u0442.\u0434.<\/p>\n<pre><code>\/\/Person.Server.cs public partial class Person {    public static readonly PropertyInfo&lt;object&gt; LastChangedProperty =             RegisterProperty&lt;object&gt;( c =&gt; c.LastChanged );     public object LastChanged {       get { return ReadProperty( LastChangedProperty ); }       private set { LoadProperty( LastChangedProperty, value ); }    }     protected override void DataPortal_Create( ) {       BusinessRules.CheckRules( );    }     private void DataPortal_Fetch( SingleCriteria&lt;Person, int&gt; idCriteria ) {       const string query = @&quot;SELECT id                                     ,first_name                                    ,second_name                                    ,age                                    ,comment                                    ,last_changed                                    ,address_id                                    ,first_address                                    ,second_address                                FROM All_persons                               WHERE id = :p_id&quot;;        using ( var manager = ConnectionManager&lt;OracleConnection&gt;.GetManager( &quot;CSLAPROJECT&quot; ) ) {           using ( var command = manager.Connection.CreateCommand( ) ) {              command.CommandType = CommandType.Text;              command.CommandText = query;              command.Parameters.AddWithValue( &quot;p_id&quot;, idCriteria.Value );              using ( var reader =                            new SafeDataReader( command.ExecuteReader( CommandBehavior.SingleRow ) ) ) {                 if ( reader.Read( ) ) {                    FetchFromReader( reader );                 }              }           }           LoadProperty( OrdersProperty, Orders.GetOrders( this ) );        }    }     private void FetchFromReader( SafeDataReader reader ) {       LoadProperty( FirstNameProperty, reader.GetString( &quot;first_name&quot; ) );       LoadProperty( SecondNameProperty, reader.GetString( &quot;second_name&quot; ) );       LoadProperty( CommentProperty, reader.GetString( &quot;comment&quot; ) );       LoadProperty( AddressProperty, Address.GetAddress( reader ) );       Id = reader.GetInt32( &quot;Id&quot; );       LastChanged = reader[ &quot;last_changed&quot; ];    }     protected override void DataPortal_Insert( ) {       using ( var manager = ConnectionManager&lt;OracleConnection&gt;.GetManager( &quot;CSLAPROJECT&quot; ) ) {          using ( var transaction = manager.Connection.BeginTransaction( ) ) {             try {                using ( var command = manager.Connection.CreateCommand( ) ) {                   command.CommandType = CommandType.StoredProcedure;                   command.CommandText = &quot;csla_project.add_person&quot;;                   var personParameters = GetPersonParameters( );                   command.Parameters.AddRange( personParameters );                   command.Transaction = transaction;                   command.ExecuteNonQuery( );                   Id = ( int )command.Parameters[ &quot;p_id&quot; ].Value;                   LastChanged = command.Parameters[ &quot;p_last_changed&quot; ];                }                FieldManager.UpdateChildren( this, transaction );                transaction.Commit( );             }              catch {                transaction.Rollback( );                throw;             }          }       }    }     protected override void DataPortal_Update( ) {       using ( var manager = ConnectionManager&lt;OracleConnection&gt;.GetManager( &quot;CSLAPROJECT&quot; ) ) {          using ( var transaction = manager.Connection.BeginTransaction( ) ) {             try {                using ( var command = manager.Connection.CreateCommand( ) ) {                   command.CommandType = CommandType.StoredProcedure;                   command.CommandText = &quot;csla_project.add_person&quot;;                   var personParameters = GetPersonParameters( );                   command.Parameters.AddRange( personParameters );                   command.Transaction = transaction;                   command.ExecuteNonQuery( );                   LastChanged = command.Parameters[ &quot;p_last_changed&quot; ];                }                FieldManager.UpdateChildren( this, transaction );                transaction.Commit( );             }              catch {                transaction.Rollback( );                throw;             }          }       }    }     private void DataPortal_Delete( SingleCriteria&lt;Person, int&gt; idCriteria  ) {       DoDelete( idCriteria.Value );    }     protected override void DataPortal_DeleteSelf( ) {       DoDelete( Id );    }     private void DoDelete( int personId ) {       using ( var manager = ConnectionManager&lt;OracleConnection&gt;.GetManager( &quot;CSLAPROJECT&quot; ) ) {          using ( var transaction = manager.Connection.BeginTransaction( ) ) {             try {                using ( var command = manager.Connection.CreateCommand( ) ) {                   command.CommandType = CommandType.StoredProcedure;                   command.CommandText = &quot;csla_project.delete_person&quot;;                   command.Parameters.AddWithValue( &quot;p_id&quot;, personId );                   command.Transaction = transaction;                   command.ExecuteNonQuery( );                }                transaction.Commit( );             }              catch {                transaction.Rollback( );                throw;             }          }       }    }     private OracleParameter[] GetPersonParameters( ) {       return new[] {          new OracleParameter( &quot;p_id&quot;, Id ) {Direction = ParameterDirection.InputOutput},          new OracleParameter( &quot;p_first_name&quot;, FirstName ),          new OracleParameter( &quot;p_second_name&quot;, SecondName ),          new OracleParameter( &quot;p_age&quot;, Age ),          new OracleParameter( &quot;p_comment&quot;, Comment ),          new OracleParameter( &quot;p_last_changed&quot;, OracleType.Int32 ) {Direction = ParameterDirection.Output}       };    } } <\/code><\/pre>\n<p>  \u041a\u043e\u0434 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a DAL \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 Person \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u0440\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 Person \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u043f\u043e\u0440\u0442\u0430\u043b\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u0430\u043c\u043e\u0433\u043e \u0441\u0435\u0431\u044f \u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 ADO .NET, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b DataPortal_XYZ \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>\/\/Orders.Server.cs public partial class Orders {    internal static Orders GetOrders( Person person ) {       return DataPortal.FetchChild&lt;Orders&gt;( person );    }     private void Child_Fetch( Person person ) {       const string query = @&quot;SELECT id                                     ,description                                FROM All_orders                               WHERE person_id = :p_person_id&quot;;       using ( var manager = ConnectionManager&lt;OracleConnection&gt;.GetManager( &quot;CSLAPROJECT&quot; ) ) {          using ( var command = manager.Connection.CreateCommand( ) ) {             command.CommandType = CommandType.Text;             command.CommandText = query;             command.Parameters.AddWithValue( &quot;p_person_id&quot;, person.Id );             using ( var reader =                           new SafeDataReader( command.ExecuteReader( CommandBehavior.SingleRow ) ) ) {                RaiseListChangedEvents = false;                while ( reader.Read( ) ) {                   Add( Order.GetOrder( reader ) );                }                RaiseListChangedEvents = true;             }          }       }    }     private void Child_Update( Person person, OracleTransaction transaction ) {       base.Child_Update( person, transaction );    } } <\/code><\/pre>\n<pre><code>\/\/Order.Server.cs public partial class Order {     internal static Order GetOrder( SafeDataReader reader ) {       return DataPortal.FetchChild&lt;Order&gt;( reader );    }     private void Child_Fetch( SafeDataReader reader ) {       LoadProperty( IdProperty, reader.GetInt32( &quot;id&quot; ) );       LoadProperty( DescriptionProperty, reader.GetString( &quot;description&quot; ) );    }     private void Child_Insert( Person person, OracleTransaction transaction ) {       using ( var manager = ConnectionManager&lt;OracleConnection&gt;.GetManager( &quot;CSLAPROJECT&quot; ) ) {          using ( var command = manager.Connection.CreateCommand( ) ) {             command.CommandType = CommandType.StoredProcedure;             command.CommandText = &quot;csla_project.add_order&quot;;             command.Transaction = transaction;             command.Parameters.AddRange( GetParameters( ) );             command.Parameters.AddWithValue( &quot;person_id&quot;, person.Id );             command.ExecuteNonQuery( );             Id = ( int )command.Parameters[ &quot;p_id&quot; ].Value;          }       }    }     private void Child_Update( Person person, OracleTransaction transaction ) {       using ( var manager = ConnectionManager&lt;OracleConnection&gt;.GetManager( &quot;CSLAPROJECT&quot; ) ) {          using ( var command = manager.Connection.CreateCommand( ) ) {             command.CommandType = CommandType.StoredProcedure;             command.CommandText = &quot;csla_project.edit_order&quot;;             command.Transaction = transaction;             command.Parameters.AddRange( GetParameters( ) );             command.Parameters.AddWithValue( &quot;person_id&quot;, person.Id );             command.ExecuteNonQuery( );          }       }    }     private void Child_DeleteSelf( Person person, OracleTransaction transaction ) {       using ( var manager = ConnectionManager&lt;OracleConnection&gt;.GetManager( &quot;CSLAPROJECT&quot; ) ) {          using ( var command = manager.Connection.CreateCommand( ) ) {             command.CommandType = CommandType.StoredProcedure;             command.CommandText = &quot;csla_project.remove_order&quot;;             command.Transaction = transaction;             command.Parameters.AddWithValue( &quot;p_person_id&quot;, person.Id );             command.Parameters.AddWithValue( &quot;p_order_id&quot;, Id );             command.ExecuteNonQuery( );          }       }    }     private OracleParameter[] GetParameters( ) {       return new[] {          new OracleParameter( &quot;p_id&quot;, Id ) {Direction = ParameterDirection.InputOutput},          new OracleParameter( &quot;p_description&quot;, Description )       };    } } <\/code><\/pre>\n<pre><code>\/\/Address.Server.cs public sealed partial class Address {    internal static Address GetAddress( SafeDataReader reader ) {       return DataPortal.Fetch&lt;Address&gt;( reader );    }     private void Child_Fetch( SafeDataReader reader ) {       using ( BypassPropertyChecks ) {          LoadProperty( IdProperty, reader.GetInt32( &quot;address_id&quot; ) );          LoadProperty( FirstAddressProperty, reader.GetString( &quot;first_address&quot; ) );          LoadProperty( SecondAddressProperty, reader.GetString( &quot;second_address&quot; ) );       }    }     private void Child_Insert( Person person, OracleTransaction transaction ) {       using ( var manager = ConnectionManager&lt;OracleConnection&gt;.GetManager( &quot;CSLAPROJECT&quot; ) ) {          using ( var command = manager.Connection.CreateCommand( ) ) {             command.CommandType = CommandType.StoredProcedure;             command.CommandText = &quot;csla_project.add_address&quot;;             command.Parameters.AddRange( GetParameters( ) );             command.Parameters.AddWithValue( &quot;p_person_id&quot;, person.Id );             command.Transaction = transaction;             command.ExecuteNonQuery( );             Id = ( int )command.Parameters[ &quot;p_id&quot; ].Value;          }       }    }     private void Child_Update( Person person, OracleTransaction transaction ) {       using ( var manager = ConnectionManager&lt;OracleConnection&gt;.GetManager( &quot;CSLAPROJECT&quot; ) ) {          using ( var command = manager.Connection.CreateCommand( ) ) {             command.CommandType = CommandType.StoredProcedure;             command.CommandText = &quot;csla_project.edit_address&quot;;             command.Parameters.AddRange( GetParameters( ) );             command.Parameters.AddWithValue( &quot;p_person_id&quot;, person.Id );             command.Transaction = transaction;             command.ExecuteNonQuery( );          }       }    }     private void Child_DeleteSelf( Person person, OracleTransaction transaction ) {       using ( var manager = ConnectionManager&lt;OracleConnection&gt;.GetManager( &quot;CSLAPROJECT&quot; ) ) {          using ( var command = manager.Connection.CreateCommand( ) ) {             command.CommandType = CommandType.StoredProcedure;             command.CommandText = &quot;csla_project.remove_address&quot;;             command.Parameters.AddWithValue( &quot;p_address_id&quot;, Id );             command.Parameters.AddWithValue( &quot;p_person_id&quot;, person.Id );             command.Transaction = transaction;             command.ExecuteNonQuery( );          }       }    }     private OracleParameter[] GetParameters( ) {       return new[] {          new OracleParameter( &quot;p_id&quot;, Id ) {Direction = ParameterDirection.InputOutput},          new OracleParameter( &quot;p_first_address&quot;, FirstAddress ),          new OracleParameter( &quot;p_second_address&quot;, SecondAddress )       };    } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<h2>Repository pattern<\/h2>\n<p>  \u041f\u043e\u043a\u0430 \u0447\u0442\u043e \u043c\u044b \u0432\u0438\u0434\u0435\u043b\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0431\u0438\u0437\u043d\u0435\u0441-\u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 CSLA, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0447\u0430\u0441\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u043a\u043e\u0434\u0435 \u043c\u043d\u043e\u0433\u0438\u0445 \u043b\u0435\u0433\u0430\u0441\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 CSLA .NET. \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u043a\u043e\u0434\u0430, \u0441\u043b\u043e\u0439 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u0438 \u0441\u043b\u043e\u0439 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0438 \u0442\u0435\u0441\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c. \u0415\u0441\u043b\u0438 \u043c\u044b \u0430\u0431\u0441\u0442\u0440\u0430\u0433\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u043e\u0442 \u0441\u043b\u043e\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c, \u0442\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u043c\u0441\u044f \u043e\u0442 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0445 \u0434\u0435\u0442\u0430\u043b\u0435\u0439 \u0432 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0435 \u0438 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d\u0438 \u0438\u043c\u0435\u044e\u0442. \u042d\u0442\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430\u0448\u0438\u0445 \u0431\u0438\u0437\u043d\u0435\u0441-\u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043c\u0435\u043d\u044f\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u043b\u043e\u0433\u0438\u043a\u0438 \u0431\u0438\u0437\u043d\u0435\u0441 \u0443\u0440\u043e\u0432\u043d\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u043a\u043e\u0441\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0438 \u0441\u043b\u043e\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u043c <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/ff649690.aspx\">\u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c Repository<\/a>. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438:<\/p>\n<pre><code>\/\/IPersonRepository.cs public interface IPersonRepository {    PersonData FindPerson( int id );     void AddPerson( PersonData newPerson, out int newId, out object lastChanged );     void EditPerson( PersonData existingPerson, out object lastChanged );     void RemovePerson( int personId ); } <\/code><\/pre>\n<p>  \u041a\u043b\u0430\u0441\u0441 PersonData \u2013 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 ( DTO, Data Transfer Object ):<\/p>\n<pre><code>\/\/PersonData.cs public sealed class PersonData {    public int Id { get; set; }     public string FirstName { get; set; }     public string SecondName { get; set; }     public int Age { get; set; }     public string Comment { get; set; }     public object LastChanged { get; set; }         } <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442 \u043a\u043e\u0434\u0430 ADO .NET \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b IContext \u0438 ITransaction:<\/p>\n<pre><code>\/\/IContext.cs public interface IContext {    ITransaction BeginTransaction( ); }  \/\/ITransaction.cs public interface ITransaction : IDisposable {    void Commit( );     void Rollback( ); } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b, \u0447\u0442\u043e\u0431\u044b \u0432 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 DataPortal_XYZ \u043a\u043b\u0430\u0441\u0441\u0430 Person \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e DAL \u043a\u043e\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432. \u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0430 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0432 \u0431\u0438\u0437\u043d\u0435\u0441-\u043e\u0431\u044a\u0435\u043a\u0442 Person. \u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u2013 \u043f\u0440\u043e\u0442\u0430\u0449\u0438\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 Person \u043d\u0435\u043b\u044c\u0437\u044f \u0438\u0437-\u0437\u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 CSLA (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0430\u0431\u0440\u0438\u0447\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443.<\/p>\n<h2>Setter Method injection<\/h2>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043a\u043b\u0430\u0441\u0441 Person \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0435 \u043f\u043e\u043b\u0435 \u0442\u0438\u043f\u0430 IPersonRepository:<\/p>\n<pre><code>[NonSerialized] [NotUndoable]  private IPersonRepository _personRepository; <\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 [NonSerialized] [NotUndoable] \u2013 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c IPersonRepository \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Person \u043e\u0442 \u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0443\u0437\u043b\u0430 \u043a \u0434\u0440\u0443\u0433\u043e\u043c\u0443 (Mobile Object Pattern) \u0438 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u043c\u043d\u043e\u0433\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u0439 \u043e\u0442\u043c\u0435\u043d\u0435 CSLA (N-Level Undo).<\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f:<\/p>\n<pre><code>[Inject] \/\/ \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 DI-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 Ninject private void Configure( IPersonRepository personRepository ) {    _personRepository = personRepository; } <\/code><\/pre>\n<p>  \u0412\u043c\u0435\u0441\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e PersonRepository (\u0442.\u043d. Property Setter Injection):<\/p>\n<pre><code>[Inject] [EditorBrowsable( EditorBrowsableState.Never )] private IPersonRepository PersonRepository {    get { return _personRepository; }    set { _personRepository = value; } } <\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e PersonRepository \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043f\u043e\u0440\u0442\u0430\u043b\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0440\u044b\u0442\u044c \u043e\u0442 Intellisence \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 EditorBrowsable.<br \/>  \u0412 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 CSLA \u0431\u0438\u0437\u043d\u0435\u0441-\u043e\u0431\u044a\u0435\u043a\u0442 \u043c\u043e\u0436\u043d\u043e, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u044f\u043a\u043e\u0440\u044f\u043c\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 BusinessBase: DataPortal_OnDataPortalInvoke, Child_OnDataPortalInvoke \u0438 OnDeserialized. \u041f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u043f\u043e\u0440\u0442\u0430\u043b\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 DataPortal_XXX \u0431\u0438\u0437\u043d\u0435\u0441-\u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u041f\u0435\u0440\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u2013 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u0431\u0438\u0437\u043d\u0435\u0441-\u043e\u0431\u044a\u0435\u043a\u0442 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u0440\u043d\u0435\u0432\u044b\u043c, \u0432\u0442\u043e\u0440\u043e\u0439 \u2013 \u0435\u0441\u043b\u0438 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c. \u0422\u0440\u0435\u0442\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u0438\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0435. \u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 Repository \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e (\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435), \u043d\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u043e\u0431\u0449\u0435\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u044f \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0432 \u0431\u0438\u0437\u043d\u0435\u0441-\u043e\u0431\u044a\u0435\u043a\u0442\u044b CSLA.<\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 Inject, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043e \u0432\u0441\u0435\u0445 \u0442\u0440\u0435\u0445 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u0438 \u0432\u043d\u0435\u0434\u0440\u044f\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 CSLA \u0431\u0438\u0437\u043d\u0435\u0441-\u043e\u0431\u044a\u0435\u043a\u0442. \u0418\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0432\u0441\u0435\u0433\u043e \u0432\u044b\u0448\u0435\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0441\u0442\u0435\u0440\u0435\u043e\u0442\u0438\u043f InjectableBusinessBase, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u0442 \u0437\u0430\u043c\u0435\u043d\u043e\u0439 \u0434\u043b\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u0441\u0442\u0435\u0440\u0435\u043e\u0442\u0438\u043f\u0430 BusinessBase:<\/p>\n<pre><code>\/\/InjectableBusinessBase.cs [Serializable] public abstract class InjectableBusinessBase&lt;T&gt; : BusinessBase&lt;T&gt; where T : BusinessBase&lt;T&gt; {    protected override void DataPortal_OnDataPortalInvoke( DataPortalEventArgs e ) {       Inject( );       base.DataPortal_OnDataPortalInvoke( e );    }     protected override void Child_OnDataPortalInvoke( DataPortalEventArgs e ) {       Inject( );       base.Child_OnDataPortalInvoke( e );    }     protected override void OnDeserialized( System.Runtime.Serialization.StreamingContext context ) {       Inject( );       base.OnDeserialized( context );    }     private void Inject( ) {       \/\/ \u0417\u0434\u0435\u0441\u044c \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043a\u043e\u0434 \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 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430.    } } <\/code><\/pre>\n<p>  \u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0442\u0435\u0440\u0435\u043e\u0442\u0438\u043f\u0430 \u0431\u0438\u0437\u043d\u0435\u0441-\u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 CSLA \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d \u043d\u043e\u0432\u044b\u0439 \u0441\u0442\u0435\u0440\u0435\u043e\u0442\u0438\u043f \u0441 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u044f\u043a\u043e\u0440\u044f\u043c\u0438. \u041a\u043e\u0434 \u043d\u043e\u0432\u044b\u0445 \u0441\u0442\u0435\u0440\u0435\u043e\u0442\u0438\u043f\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d \u043a\u043e\u0434\u0443 \u0432\u044b\u0448\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043b\u0430\u0441\u0441\u044b \u0431\u0438\u0437\u043d\u0435\u0441-\u0443\u0440\u043e\u0432\u043d\u044f \u0441 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u043c \u0441\u0442\u0435\u0440\u0435\u043e\u0442\u0438\u043f\u0430\u043c:<\/p>\n<pre><code>[Serializable] public partial class Person : InjectableBusinessBase&lt;Person&gt; {    \/\/\u2026 } [Serializable] public partial class Orders : InjectableBusinessListBase&lt;Orders, Order&gt; {    \/\/\u2026 } [Serializable] public partial class Address : InjectableBusinessBase&lt;Address&gt; {    \/\/\u2026 } <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 Inject \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0444\u0430\u0441\u0430\u0434\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 DI-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <a href=\"http:\/\/www.ninject.org\/\">Ninject<\/a>):<\/p>\n<pre><code>\/\/Container.cs public static class Container {    private static readonly object SyncRoot = new object( );     private static volatile IKernel _kernel; \/\/ \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 DI-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f Ninject     public static IKernel Kernel {       get {          if ( _kernel == null ) {             lock ( SyncRoot ) {                if ( _kernel == null ) {                   ConfigureKernel( );                }             }          }          return _kernel;       }    }     \/\/\u041c\u0435\u0442\u043e\u0434 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0432 \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442.    public static void InjectInto( object target ) {       Kernel.Inject( target );    }     private static void ConfigureKernel( ) {       \/\/ \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430    }     public static void InjectKernel( IKernel kernel ) {       lock ( SyncRoot ) {          _kernel = kernel;       }    } } <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c DI-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043d\u0430\u043c \u043f\u043e\u043a\u0430 \u043d\u0435\u0432\u0430\u0436\u043d\u043e, \u0430 \u0432\u0430\u0436\u0435\u043d \u043b\u0438\u0448\u044c \u043c\u0435\u0442\u043e\u0434 InjectInto. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043a \u043c\u0435\u0442\u043e\u0434\u0443 Inject( ) \u0441\u0442\u0435\u0440\u0435\u043e\u0442\u0438\u043f\u0430 InjectableBusinessBase:<\/p>\n<pre><code>private void Inject( ) {    Container.InjectInto( this );  } <\/code><\/pre>\n<p>  \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 IPersonRepository \u0438 IContext \u0432 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0430 Person \u0438 \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u044b DataPortal_XYZ \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code>\/\/Person.Server.cs public partial class Person {    public static readonly PropertyInfo&lt;object&gt; LastChangedProperty =             RegisterProperty&lt;object&gt;( c =&gt; c.LastChanged );     public object LastChanged {       get { return ReadProperty( LastChangedProperty ); }       private set { LoadProperty( LastChangedProperty, value ); }    }     [NonSerialized] [NotUndoable]     private IPersonRepository _personRepository;     [Inject]    [EditorBrowsable( EditorBrowsableState.Never )]    private IPersonRepository PersonRepository {       get { return _personRepository; }       set { _personRepository = value; }    }             [NonSerialized][NotUndoable]    private IContext _context;     [Inject]    [EditorBrowsable(EditorBrowsableState.Never)]    private IContext Context {       get { return _context; }       set { _context = value; }    }     protected override void DataPortal_Create( ) {       BusinessRules.CheckRules( );    }     private void DataPortal_Fetch( SingleCriteria&lt;Person, int&gt; idCriteria ) {       var personData = PersonRepository.FindPerson( idCriteria.Value );       if ( personData != null ) {          CopyValuesFrom( personData );          LoadProperty( OrdersProperty, Orders.GetOrders( personData ) );          LoadProperty( AddressProperty, Address.GetAddress( personData ) );       }    }     private void CopyValuesFrom( PersonData personData ) {       using ( BypassPropertyChecks ) {          DataMapper.Map( personData, this );        }    }     protected override void DataPortal_Insert( ) {       using ( var transaction = Context.BeginTransaction( ) ) {          try {             var personData = GetPersonData( );             int newId;             object lastChanged;             PersonRepository.AddPerson( personData, out newId, out lastChanged );             Id = newId;             LastChanged = lastChanged;             FieldManager.UpdateChildren( personData);             transaction.Commit( );          }           catch {             transaction.Rollback( );             throw;          }       }    }     protected override void DataPortal_Update( ) {       using ( var transaction = Context.BeginTransaction( ) ) {          try {             var personData = GetPersonData( );             object lastChanged;             PersonRepository.EditPerson( personData, out lastChanged );             LastChanged = lastChanged;             FieldManager.UpdateChildren( personData );             transaction.Commit( );          }           catch {             transaction.Rollback( );             throw;          }       }    }     private PersonData GetPersonData( ) {       \/\/ \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u043c\u0435\u043d\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432        \/\/\u0431\u0438\u0437\u043d\u0435\u0441-\u043a\u043b\u0430\u0441\u0441\u0430 Person \u0438 DTO PersonData \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f        \/\/\u043a\u043b\u0430\u0441\u0441\u043e\u043c CSLA DataMapper \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 DTO, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u043e\u0434 \u0435\u0449\u0435 \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u0435\u0435.       var personData = new PersonData( );       DataMapper.Map( this, personData, OrdersProperty.Name, AddressProperty.Name );       return personData;    }     private void DataPortal_Delete( SingleCriteria&lt;Person, int&gt; idCriteria ) {       PersonRepository.RemovePerson( idCriteria.Value );    }     protected override void DataPortal_DeleteSelf( ) {       PersonRepository.RemovePerson( Id );    } } <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>\/\/Orders.Server.cs public partial class Orders {    [NonSerialized]    [NotUndoable]    private IOrderRepository _orderRepository;     [Inject]    [EditorBrowsable( EditorBrowsableState.Never )]    protected IOrderRepository OrderRepository {       get { return _orderRepository; }       set { _orderRepository = value; }    }     internal static Address GetAddress( Person person ) {       return DataPortal.FetchChild&lt;Address&gt;( person );    }     protected void Child_Fetch( PersonData person) {       var data = OrderRepository.FindOrders( person.Id );       RaiseListChangedEvents = false;       AddRange( data.Select( Order.GetOrder ) );       RaiseListChangedEvents = true;    }     protected void Child_Update( PersonData person ) {       base.Child_Update( person, OrderRepository );    } } <\/code><\/pre>\n<p>  <\/p>\n<pre><code>\/\/Order.Server.cs public partial class Order {    internal static Order GetOrder( OrderData orderData ) {       return DataPortal.FetchChild&lt;Order&gt;( orderData );    }     protected void Child_Fetch( OrderData orderData ) {       using ( BypassPropertyChecks ) {          DataMapper.Map( orderData, this );       }    }     protected void Child_Insert( PersonData person, IOrderRepository orderRepository ) {       var data = GetOrderData( );       Id = orderRepository.AddOrder( person.Id, data );    }     protected void Child_Update( PersonData person, IOrderRepository orderRepository ) {       var data = GetOrderData( );       orderRepository.EditOrder( person.Id, data );    }     protected void Child_DeleteSelf( PersonData person, IOrderRepository orderRepository ) {       orderRepository.RemoveOrder( person.Id, Id );    }     private OrderData GetOrderData( ) {       var orderData = new OrderData( );       DataMapper.Map( this, orderData );       return orderData;    } } <\/code><\/pre>\n<pre><code>\/\/Address.Server.cs public partial class Address {    [NonSerialized, NotUndoable]    private IAddressRepository _addressRepository;     [Inject]    [EditorBrowsable( EditorBrowsableState.Never )]    protected IAddressRepository AddressRepository {       get { return _addressRepository; }       set { _addressRepository = value; }    }     internal static Address GetAddress( PersonData person ) {       return DataPortal.FetchChild&lt;Address&gt;( person );    }     protected void Child_Fetch( PersonData personData ) {       using ( BypassPropertyChecks ) {          var addressData = AddressRepository.FindAddress( personData.Id );          DataMapper.Map( addressData, this );       }    }     protected void Child_Insert( PersonData person ) {       var data = GetAddressData( );       Id = AddressRepository.AddAddress( person.Id, data );    }     protected void Child_Update( PersonData person ) {       var data = GetAddressData( );       AddressRepository.EditAddress( person.Id, data );    }     protected void Child_DeleteSelf( PersonData person ) {       AddressRepository.RemoveAddress( person.Id, Id );    }     private AddressData GetAddressData( ) {       var addressData = new AddressData( );       DataMapper.Map( this, addressData );       return addressData;    } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0421\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0439 \u043a\u043e\u0434 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a DAL \u0438\u0441\u0447\u0435\u0437. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0434 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435\u043c \u043a \u043c\u0435\u0442\u043e\u0434\u0430\u043c DataPortal_XYZ \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u043f\u043e\u0440\u0442\u0430\u043b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u044f\u043a\u043e\u0440\u0435\u0439 \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442 \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 Person, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a DAL \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u0432.<\/p>\n<p>  \u0418\u0434\u0435\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0432\u0437\u044f\u0442\u0430 \u0438\u0437 <a href=\"https:\/\/jonnybekkum.wordpress.com\/2010\/12\/30\/cslacontrib-mef-and-repository-pattern-with-csla4\/\">\u0431\u043b\u043e\u0433\u0430 Johny Bekkum<\/a>. \u0418\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <a href=\"https:\/\/github.com\/marimerllc\/cslacontrib\">CSLAContrib<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0439 \u043a CSLA. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0432 \u043d\u0435\u0439 \u0435\u0441\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u0441\u0442\u0435\u0440\u0435\u043e\u0442\u0438\u043f\u043e\u0432 CSLA, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u0445 Property Setter Injection. \u041a\u043e\u0434 \u044d\u0442\u0438\u0445 \u0441\u0442\u0435\u0440\u0435\u043e\u0442\u0438\u043f\u043e\u0432 \u043f\u043e\u0434\u043e\u0431\u0435\u043d \u043a\u043e\u0434\u0443, \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c\u0443 \u0432\u044b\u0448\u0435. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 DI-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <a href=\"https:\/\/msdn.microsoft.com\/ru-ru\/library\/dd460648(v=vs.110).aspx\">MEF<\/a> (Managed Extensibility Framework), \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u0432 .NET Framework 4.0.<\/p>\n<p>  \u041e\u0442\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u0432\u0441\u0435\u0445 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c, \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432 Container \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e:<\/p>\n<pre><code>private IPersonRepository GetPersonRepository {    return Core.Container.Kernel.Get&lt;IPersonRepository&gt;(); } <\/code><\/pre>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043b\u0430\u0441\u0441 Container \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a Service Locator, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0447\u0430\u0441\u0442\u043e <a href=\"http:\/\/blog.ploeh.dk\/2010\/02\/03\/ServiceLocatorisanAnti-Pattern\/\">\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 \u043a\u0430\u043a \u0430\u043d\u0442\u0438\u043f\u0430\u0442\u0442\u0435\u0440\u043d<\/a>. \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0442\u043e\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u0435\u043d, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u0440\u0438 \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0435\u043d\u0438\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043b\u0435\u0433\u0430\u0441\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043d\u0430 CSLA.<\/p>\n<h2>CSLA via Repository Pattern<\/h2>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0448\u0430\u0431\u043b\u043e\u043d\u0430 Repository. \u0412\u044b\u043d\u0435\u0441\u0435\u043c \u043e\u0431\u0449\u0438\u0439 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u0432 \u043a\u043e\u0434 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0411\u0414 Oracle \u0432 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 RepositoryBase:<\/p>\n<pre><code>\/\/RepositoryBase.cs internal class RepositoryBase {    private readonly string _databaseName;     protected RepositoryBase( string databaseName ) {       _databaseName = databaseName;    }     protected virtual void ExecuteProcedure( string procName, params OracleParameter[] parameters ) {       using ( var manager =                   TransactionManager&lt;OracleConnection, OracleTransaction&gt;.GetManager( _databaseName ) ) {          using ( var command = manager.Connection.CreateCommand( ) ) {             command.CommandType = CommandType.StoredProcedure;             command.CommandText = procName;             command.Transaction = manager.Transaction;             if ( parameters != null ) {                command.Parameters.AddRange( parameters );             }             command.ExecuteNonQuery( );             if ( manager.RefCount == 1 ) {                manager.Commit( );             }          }       }    }     protected virtual IEnumerable&lt;T&gt; GetRows&lt;T&gt;( string query,                Func&lt;SafeDataReader, T&gt; fetchFromReader, params OracleParameter[] parameters ) {       using ( var manager = ConnectionManager&lt;OracleConnection&gt;.GetManager( _databaseName ) ) {          using ( var command = manager.Connection.CreateCommand( ) ) {             command.CommandType = CommandType.Text;             command.CommandText = query;             if ( parameters != null ) {                command.Parameters.AddRange( parameters );             }                                 using ( var reader = new SafeDataReader( command.ExecuteReader( ) ) ) {                while ( reader.Read( ) ) {                   yield return fetchFromReader( reader );                }             }          }       }    } } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442 IPersonRepository, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f RepositoryBase:<\/p>\n<pre><code>\/\/PersonRepository.cs internal sealed class PersonRepository : RepositoryBase, IPersonRepository {    public PersonRepository( ) : base( &quot;CSLAPROJECT&quot; ) { }     public PersonData FindPerson( int id ) {       const string query = @&quot;SELECT id                                     ,first_name                                    ,second_name                                    ,age                                    ,comment                                    ,last_changed                                FROM All_persons                               WHERE id = :p_id&quot;;       return GetRows( query, FetchFromReader, new OracleParameter( &quot;p_id&quot;, id ) ).First( );    }     public void AddPerson( PersonData newPerson, out int newId, out object lastChanged ) {       var parameters = GetPersonParameters( newPerson );       ExecuteProcedure( &quot;csla_project.add_person&quot;, parameters );       newId = ( int )parameters.First( ).Value;       lastChanged = parameters.Last( ).Value;    }     public void EditPerson( PersonData existingPerson, out object lastChanged ) {       var parameters = GetPersonParameters( existingPerson );       ExecuteProcedure( &quot;csla_project.update_person&quot;, parameters );       lastChanged = parameters.Last( ).Value;    }     public void RemovePerson( int personId ) {       ExecuteProcedure( &quot;csla_project.delete_person&quot;, new OracleParameter(&quot;p_id&quot;, personId) );    }     private PersonData FetchFromReader( SafeDataReader reader ) {       return new PersonData {          Id = reader.GetInt32( &quot;id&quot; ),          FirstName = reader.GetString( &quot;first_name&quot; ),          SecondName = reader.GetString( &quot;second_name&quot; ),          Age = reader.GetInt32( &quot;age&quot; ),          Comment = reader.GetString( &quot;comment&quot; ),          LastChanged = reader[&quot;last_changed&quot;]        };    }     private OracleParameter[] GetPersonParameters( PersonData personData ) {       return new[] {          new OracleParameter( &quot;p_id&quot;, personData.Id ){Direction = ParameterDirection.InputOutput},          new OracleParameter( &quot;p_first_name&quot;, personData.FirstName ),          new OracleParameter( &quot;p_second_name&quot;, personData.SecondName ),          new OracleParameter( &quot;p_age&quot;, personData.Age ),          new OracleParameter( &quot;p_comment&quot;, personData.Comment ),          new OracleParameter( &quot;p_last_changed&quot;, OracleType.Int32 ) {             Value = personData.LastChanged,              Direction = ParameterDirection.Output          }       };    } } <\/code><\/pre>\n<p>  \u041a\u043b\u0430\u0441\u0441\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code>\/\/Context.cs internal sealed class Context : IContext {    ITransaction IContext.BeginTransaction( ) {       return new Transaction( );    } }  \/\/Transaction.cs internal sealed class Transaction : ITransaction {    private readonly TransactionManager&lt;OracleConnection, OracleTransaction&gt; _manager =           TransactionManager&lt;OracleConnection, OracleTransaction&gt;.GetManager( &quot;CSLAPROJECT&quot; );     void ITransaction.Commit( ) {       _manager.Commit( );       Dispose( );    }     void ITransaction.Rollback( ) {       Dispose( );    }     public void Dispose( ) {       _manager.Dispose( );    } } <\/code><\/pre>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u0431\u044b\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u043a\u043b\u0430\u0441\u0441 CSLA <a href=\"https:\/\/github.com\/nschonni\/csla-svn\/blob\/master\/Source\/Csla\/Data\/TransactionManager.cs\">TransactionManager<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0438 \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0441 \u043d\u0438\u043c ADO .NET \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e \u0432\u043e \u0432\u0441\u0435\u043c \u0433\u0440\u0430\u0444\u0435 \u0431\u0438\u0437\u043d\u0435\u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043e\u0434\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0440\u0442\u0430\u043b\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u043b\u0430\u0441\u0441\u044b AddressRepository \u0438 OrderRepository \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c\u0443 \u0432\u044b\u0448\u0435 PersonRepository.<\/p>\n<p>  \u0414\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0432\u0441\u0435\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/735\/ac2\/f04\/735ac2f0442b4b139c75e26355ccb4ce.png\"\/><\/p>\n<p>  \u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0431\u0438\u0437\u043d\u0435\u0441-\u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u0438 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u044b \u043f\u043e \u0440\u0430\u0437\u043d\u044b\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u043c. \u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0430 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/c08\/e10\/39a\/c08e1039ada2439296e860a7064536b0.png\"\/><\/p>\n<p>  \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 CslaProject.DataAccess.OracleDb \u043c\u043e\u0434\u0443\u043b\u044c Ninject \u0434\u043b\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 DAL:<\/p>\n<pre><code>\/\/Module.cs public class Module : NinjectModule {    public override void Load( ) {       Bind&lt;IPersonRepository&gt;( ).To&lt;PersonRepository&gt;( ).InSingletonScope( );       Bind&lt;IOrderRepository&gt;( ).To&lt;OrderRepository&gt;( ).InSingletonScope( );       Bind&lt;IAddressRepository&gt;( ).To&lt;AddressRepository&gt;( ).InSingletonScope( );       Bind&lt;IGroupRepository&gt;( ).To&lt;GroupRepository&gt;( ).InSingletonScope( );       Bind&lt;IContext&gt;( ).To&lt;Context&gt;( ).InSingletonScope( );    } } <\/code><\/pre>\n<p>  <\/p>\n<h2>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430<\/h2>\n<p>  \u0412\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u043a \u0444\u0430\u0441\u0430\u0434\u043d\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443 Container \u0438 \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043c \u043a\u043e\u0434 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 DAL \u0432 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435.<\/p>\n<pre><code>private static void ConfigureKernel( ) {    \/\/ InjectNonPublic = true, \u0442.\u043a. \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0437\u0430\u043a\u0440\u044b\u0442\u044b    var kernel = new StandardKernel( new NinjectSettings {InjectNonPublic = true} );    \/\/ \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439.    var dependencyCatalogs = GetDependencyCatalogs( );    if ( dependencyCatalogs.Any( ) ) {       foreach ( var values in                     dependencyCatalogs.Select( d =&gt; ConfigurationManager.AppSettings[ d ].Split( ';' ) ) ) {          var catalogPath = Path.Combine( AppDomain.CurrentDomain.BaseDirectory, values[ 0 ] );          IEnumerable&lt;string&gt; depedencyLibNames;          if ( values.Count( ) &gt; 1 ) {             var searchPattern = values[ 1 ];             depedencyLibNames = Directory.GetFiles( catalogPath, searchPattern );          }           else {             depedencyLibNames = Directory.GetFiles( catalogPath );          }          foreach ( var file in depedencyLibNames ) {             var dependency = Assembly.LoadFile( Path.Combine( catalogPath, file ) );             kernel.Load( dependency );          }       }    }     else {       \/\/\u0415\u0441\u043b\u0438 \u043d\u0435\u0442 \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439, \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0432\u0441\u0435        \/\/\u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0435\u0441\u044f \u0432 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u043c \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u0441\u0431\u043e\u0440\u043a\u0438, \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 CslaProject       kernel.Load(&quot;CslaProject*.dll&quot;);    }    _kernel = kernel; }  private static string[] GetDependencyCatalogs( ) {    return ConfigurationManager.AppSettings.AllKeys.Where(                 p =&gt; p.StartsWith( &quot;CslaProject.Depencies&quot;, true, CultureInfo.InvariantCulture ) ).ToArray( ); } <\/code><\/pre>\n<p>  \u0427\u0438\u0442\u0430\u0435\u0442\u0441\u044f App.Config \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0430:<\/p>\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot;?&gt; &lt;configuration&gt;     &lt;appSettings&gt;     &lt;add key=&quot;CslaProject.Dependencies&quot; value=&quot;Dependencies;CslaProject*.dll&quot;\/&gt;   &lt;\/appSettings&gt;   &lt;connectionStrings&gt;     &lt;!--      &lt;add name=&quot;CSLAPROJECT&quot; providerName=&quot;System.Data.OracleClient&quot; connectionString=&quot;user id=test_user;password=12345;data source=testdb;&quot; \/&gt;     --&gt;   &lt;\/connectionStrings&gt; &lt;startup&gt;   &lt;supportedRuntime version=&quot;v4.0&quot; sku=&quot;.NETFramework,Version=v4.0&quot;\/&gt; &lt;\/startup&gt; &lt;\/configuration&gt;  <\/code><\/pre>\n<p>  \u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u0435\u043a\u0446\u0438\u0438 appSettings \u0432 \u043e\u043f\u0446\u0438\u044f\u0445 \u0441 \u043a\u043b\u044e\u0447\u043e\u043c CslaProject.Dependencies. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043e\u043f\u0446\u0438\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0432 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u043c \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u043c\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 App.Config \u0441 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 CslaProject.Dependencies (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043a\u043e\u0434 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0441 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0430\u043c\u0438 CslaProject.UnitTests), \u0442\u043e \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u0441\u0431\u043e\u0440\u043a\u0438, \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 CslaProject. \u0422\u0430\u043a, \u0435\u0441\u043b\u0438 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0441 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c Ninject, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c DAL \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u043c\u0438 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f\u043c\u0438, \u0442\u043e \u0432 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 DataPortal_XYZ \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d\u0438.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0442\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u043e\u0442 \u0431\u0438\u0437\u043d\u0435\u0441-\u043a\u043b\u0430\u0441\u0441\u043e\u0432 CSLA \u0432\u043f\u043e\u043b\u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u0435\u043d. \u041e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u0442\u044c \u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438:  <\/p>\n<ul>\n<li>\u0412\u0441\u0435 \u0431\u0438\u0437\u043d\u0435\u0441-\u043a\u043b\u0430\u0441\u0441\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u043c \u0441\u0442\u0435\u0440\u0435\u043e\u0442\u0438\u043f\u0430\u043c Injectables, \u0447\u0442\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e.<\/li>\n<li>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b. \u041c\u0435\u0442\u043e\u0434 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u0435\u0440\u0435\u0434 \u043a\u0430\u0436\u0434\u044b\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u0432 DataPortal_XYZ \u0438 \u043f\u043e\u0441\u043b\u0435 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u0438\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0435, \u0447\u0442\u043e \u0434\u043b\u044f \u0431\u0438\u0437\u043d\u0435\u0441-\u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u0447\u0438\u0441\u043b\u043e\u043c \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439.<\/li>\n<li>\u0423\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/li>\n<li>\u041f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 DI-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0443.<\/li>\n<\/ul>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u0432\u0441\u0451. \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0438 \u0434\u0430 \u043f\u0440\u0435\u0431\u0443\u0434\u0435\u0442 \u0441 \u0432\u0430\u043c\u0438 \u0421\u0438\u043b\u0430.<br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/314110\/\"> https:\/\/habrahabr.ru\/post\/314110\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c \u0441 \u043d\u0438\u0437\u043a\u043e\u0439 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0441\u0442\u044c\u044e (Low Coupling) \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432 \u043f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u041f\u041e. \u0412 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043a\u0430\u0440\u043a\u0430\u0441\u0430 <a href=\"http:\/\/cslanet.com\/\">CSLA .NET<\/a>, \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u044b\u0432\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e.<\/p>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043e\u0442\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c (Data Access Layer, DAL) \u043e\u0442 \u0441\u043b\u043e\u044f \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0438 (Business Layer) \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/ff649690.aspx\">\u0448\u0430\u0431\u043b\u043e\u043d\u0430 Repository<\/a> \u0438 \u043e\u043f\u0438\u0441\u0430\u043d \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 (Depency Injection) \u0432 \u0431\u0438\u0437\u043d\u0435\u0441-\u043e\u0431\u044a\u0435\u043a\u0442\u044b CSLA .NET. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f CSLA \u0432\u0435\u0440\u0441\u0438\u0438 4.1.  <\/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-280263","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/280263","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=280263"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/280263\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=280263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=280263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=280263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}