From 60ac2397ff1b0fa8be713ceec0876cac226c634e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 12 Jan 2018 21:11:29 +0300 Subject: [PATCH 01/14] Remove IsTransient from Entity. --- src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs | 8 +------- src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/EntityHelper.cs | 2 +- src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs | 6 ------ .../Domain/Repositories/MemoryDb/MemoryDbRepository.cs | 2 +- 4 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs index 33e7220166..7b09c60baa 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs @@ -22,12 +22,6 @@ namespace Volo.Abp.Domain.Entities /// public virtual TPrimaryKey Id { get; set; } - /// - public virtual bool IsTransient() - { - return EntityHelper.IsTransient(this); - } - /// public override bool Equals(object obj) { @@ -44,7 +38,7 @@ namespace Volo.Abp.Domain.Entities //Transient objects are not considered as equal var other = (Entity)obj; - if (IsTransient() && other.IsTransient()) + if (EntityHelper.IsTransient(this) && EntityHelper.IsTransient(other)) { return false; } diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/EntityHelper.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/EntityHelper.cs index 304d664850..2dd23b4a08 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/EntityHelper.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/EntityHelper.cs @@ -25,7 +25,7 @@ namespace Volo.Abp.Domain.Entities /// This method is exists to help developers who want to directly implement /// but want to use default IsTransient implementation as a shortcut. /// - public static bool IsTransient(IEntity entity) + public static bool IsTransient(IEntity entity) // TODO: Completely remove IsTransient { if (EqualityComparer.Default.Equals(entity.Id, default)) { diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs index 2d48ee20e7..9534c6c38d 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs @@ -20,11 +20,5 @@ namespace Volo.Abp.Domain.Entities /// Unique identifier for this entity. /// TPrimaryKey Id { get; set; } - - /// - /// Checks if this entity is transient (not persisted to database and it has not an ). - /// - /// True, if this entity is transient - bool IsTransient(); } } diff --git a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs index 01568ff066..dcccdd6b07 100644 --- a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs +++ b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs @@ -42,7 +42,7 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb { if (typeof(TPrimaryKey) == typeof(int) || typeof(TPrimaryKey) == typeof(long) || typeof(TPrimaryKey) == typeof(Guid)) { - if (entity.IsTransient()) + if (EntityHelper.IsTransient(entity)) { entity.Id = Database.GenerateNextId(); } From 6751ce6628370bb581895ad3e5da0d28a784de26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 15 Jan 2018 21:20:56 +0300 Subject: [PATCH 02/14] Do not use Entity and Repository default PK interfaces. --- .../AbpDesk/Blogging/BlogPost.cs | 2 +- .../AbpDesk/Blogging/BlogPostComment.cs | 5 +++-- src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll | Bin 15360 -> 15360 bytes .../Application/Services/ICrudAppService.cs | 8 -------- .../Abp/Identity/IIdentityRoleRepository.cs | 3 ++- .../Abp/Identity/IIdentityUserRepository.cs | 2 +- .../Volo/Abp/Identity/IdentityRole.cs | 2 +- .../Volo/Abp/Identity/IdentityRoleClaim.cs | 2 +- .../Volo/Abp/Identity/IdentityUser.cs | 2 +- .../Volo/Abp/Identity/IdentityUserClaim.cs | 2 +- .../Volo/Abp/Identity/IdentityUserLogin.cs | 2 +- .../Volo/Abp/Identity/IdentityUserRole.cs | 2 +- .../Volo/Abp/Identity/IdentityUserToken.cs | 2 +- .../Identity/EfCoreIdentityRoleRepository.cs | 2 +- .../Identity/EfCoreIdentityUserRepository.cs | 2 +- .../ApiResources/ApiResource.cs | 2 +- .../IdentityServer/ApiResources/ApiScope.cs | 2 +- .../ApiResources/IApiResourceRepository.cs | 5 +++-- .../Volo/Abp/IdentityServer/Clients/Client.cs | 2 +- .../Abp/IdentityServer/Clients/ClientClaim.cs | 2 +- .../Clients/ClientCorsOrigin.cs | 2 +- .../Clients/ClientIdPRestriction.cs | 2 +- .../Clients/ClientPostLogoutRedirectUri.cs | 2 +- .../IdentityServer/Clients/ClientProperty.cs | 2 +- .../Clients/ClientRedirectUri.cs | 2 +- .../Abp/IdentityServer/Clients/ClientScope.cs | 2 +- .../Clients/IClientRepository.cs | 5 +++-- .../Grants/IPersistentGrantRepository.cs | 5 +++-- .../IdentityServer/Grants/PersistedGrant.cs | 2 +- .../Grants/PersistedGrantStore.cs | 2 -- .../IIdentityResourceRepository.cs | 5 +++-- .../IdentityResources/IdentityResource.cs | 2 +- .../Volo/Abp/IdentityServer/Secret.cs | 2 +- .../Volo/Abp/IdentityServer/UserClaim.cs | 2 +- .../IdentityServer/ApiResourceRepository.cs | 5 +++-- .../Abp/IdentityServer/ClientRepository.cs | 5 +++-- .../IdentityResourceRepository.cs | 5 +++-- .../PersistedGrantRepository.cs | 5 +++-- .../Abp/MultiTenancy/ITenantRepository.cs | 2 +- .../Volo/Abp/MultiTenancy/Tenant.cs | 2 +- .../MultiTenancy/TenantConnectionString.cs | 2 +- .../MultiTenancy/EfCoreTenantRepository.cs | 2 +- .../Abp/AutoMapper/SampleClasses/MyEntity.cs | 5 +++-- .../RepositoryRegistration_Tests.cs | 7 +++---- .../SecondContext/BookInSecondDbContext.cs | 5 +++-- .../SecondContextTestDataBuilder.cs | 7 ++++--- .../ThirdDbContextDummyEntity.cs | 5 +++-- .../DataFiltering/MultiTenant_Filter_Tests.cs | 4 ++-- .../DataFiltering/SoftDelete_Filter_Tests.cs | 7 ++++--- .../DbContext_Replace_Tests.cs | 7 ++++--- .../Repositories/Basic_Repository_Tests.cs | 8 ++++---- .../EntityFrameworkCore/Transaction_Tests.cs | 8 ++++---- .../PersonAppServiceClientProxy_Tests.cs | 4 ++-- .../DataFilters/MultiTenant_Filter_Tests.cs | 4 ++-- .../Volo/Abp/TestApp/Domain/Person.cs | 2 +- .../Volo/Abp/TestApp/TestDataBuilder.cs | 4 ++-- 56 files changed, 99 insertions(+), 94 deletions(-) diff --git a/src/AbpDesk/AbpDesk.MongoBlog/AbpDesk/Blogging/BlogPost.cs b/src/AbpDesk/AbpDesk.MongoBlog/AbpDesk/Blogging/BlogPost.cs index 1ead1ae0d5..004b14843c 100644 --- a/src/AbpDesk/AbpDesk.MongoBlog/AbpDesk/Blogging/BlogPost.cs +++ b/src/AbpDesk/AbpDesk.MongoBlog/AbpDesk/Blogging/BlogPost.cs @@ -6,7 +6,7 @@ using Volo.Abp.Domain.Entities; namespace AbpDesk.Blogging { - public class BlogPost : AggregateRoot + public class BlogPost : AggregateRoot { public virtual string Title { get; protected set; } diff --git a/src/AbpDesk/AbpDesk.MongoBlog/AbpDesk/Blogging/BlogPostComment.cs b/src/AbpDesk/AbpDesk.MongoBlog/AbpDesk/Blogging/BlogPostComment.cs index f8298acc4d..b352faa92a 100644 --- a/src/AbpDesk/AbpDesk.MongoBlog/AbpDesk/Blogging/BlogPostComment.cs +++ b/src/AbpDesk/AbpDesk.MongoBlog/AbpDesk/Blogging/BlogPostComment.cs @@ -1,9 +1,10 @@ -using JetBrains.Annotations; +using System; +using JetBrains.Annotations; using Volo.Abp.Domain.Entities; namespace AbpDesk.Blogging { - public class BlogPostComment : Entity + public class BlogPostComment : Entity { [NotNull] public virtual string Name { get; protected set; } diff --git a/src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll b/src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll index 879b5f90bd5119f9448d4fee92d477a960437704..a6bb0c90e4f934c925e089b4398fc610bba4a6ab 100644 GIT binary patch delta 3019 zcmZuz4RBOf75>h>Z{N>u-plSL8$&`vHYp*2Bo-ks1tQ6mhQ`832r$snfq+cRAkdJg zKpi##g(@%*SD9k}!1B{dE5${W3We1C7~3MWg9VH&v_P%YB34@zZ9Mnx%8(gv=6&yc z-#Pc5yZ7h3w5@7ewe3-(=C^B)AKd&kNml%yayVIuVa6g!f%rP>d}V$BC|nC{=67*A z+x4w0o0d1WfZL%QpkJ~!yB^!}fFNsyQ)kys;rCAFr{X*85i~R2X^)R_cMv}wKimZ( zWdqMyN(W3#H@EpsJgu?csPw1fh+paD<{{g}293)!ZuTi9;A`gilZL{5zEaD?Rju1P zW*FOk>@oI{hm$d9D}`|pzv0lRF~Fg-d@9)rUnS#8GzR?mwY!f@Y=hDhhQgz+ihN6I zMeFC$$T9u4(%;3#8{@mkgxmp~v22=b+iUV&}m!Vw>y&JcrNB zFxFTHydr$+%-{qMKn=8-F$>>vYVDE8bFW(E80V{@EG+OU7;CHwPI;OWhtY|DbFVz1 zdadCVGVxc9>$LX!7vQxGPJmlLUWk|wTk`zb1JEXw#n)P6TzlfO|RiQm7v&*DJ zwq_leMPsFb7Yme64Z~Z2qnh=gE-+F0@a7<2zh)iTY5p4ap-_+MOqSg-^1;@$%c+$? z9wwA>_IurYyoRKFm%SigxPp}L2kw`og^?-WE_W8QF`9i_PsT=-W@>5+q>YXwLp^5* z;91RjFwg3ySQ`GAq|ScXO=-BSS(kH&L(}k4%D0t6U3`-A?XZGyF_7{_oUcj`)}87% zbvb!XGqa#(J3}Up#yERs8tYwU#PTTV|HfU_p*sO82#vP1Y_ZUqsQ3_8(t=?&< zRlCkg%!EUxzX(l?LF{52hjtx06fMSF4292YVBBCW=c{A-+i--&dmB)y?M|9$>_s2F zV;)14DxD8;jv~h27~c>#d8>w{d-MV2*+ZyAdr4&5CFF>Yy-AD%?(`T%#n0V&R81|$ z5*mwu_YInYUfM!;(-Ve?(PAlMh^J+uSz`yvfMUZFan&wo_>)V)f5+C5Kv-}8wE5#YbESVti-3m-bA zVm@xtyEGJ+sEX}V?iFelKk*(ALvhY-U_9?`p>}cE-zXYrqq|&mh_loxJlNPK!l=bT z#_5dZeED9G<;cKc#$23{v||%1?f4ZA8tak3FMYeTvP&zS+V0f$MZ{F-MNQt* z4kD!xsm@Z{(G)7BO54>bRLVkaw`ts|@r1?;NnNPXc4|DK@q$K3rRU2{Gx=4e$-<;$ zJi|&2UPGKZ=`Fg>^^v&p8GPC2$nAV>KJXOoaeu`4x>laFlv3dAX8ecP9zPyxSX_om zz9HYllUPb?={xiipMwfvw5iK?dt1bxJHFGm+FH@0>FwG^QKZsyQ=h~CwXN~?a0b1q zu|i>NijErGb9b7GAFQp>+ThVBcZlEN%SWiaB0ZlX;o1B&Q-ZvVih%cr{Ie0~Rq*o=zIq zRjwTnDFPJSg%CtlK>@{4;s)wMc(}+;i3tcbatmoNP#`ExXeky*m?DVUGvjT9rCjNL zd;W9IoS8d!X6`n=-uU{KUmByn>bQ1b(=tiE*gaW5zP3k=mnHdQZ(2PQ@&iEL8^9L+ zElFg%s%~}d^2KYwS9=C8v(azjZOt=AsXr0#b2Ag!=3d*xYnm@;{=%m`_l;`KKd!mmmuZ=} zp#A^ROl118&Dc&Zj(d(rVRYj#H%KyiIdzgxb@r04l(`yn1Aepxx08u2Q2srJ;)g+% zc~UC7P5Vz{F6W%FmH$uNHVw0Q##}6v9%W#^&q>Tcvvd-(ama44GqA$_!p_EB={4B7 zcpo>-FqT-YZXv#L%DL!|p$gSA)3D4LYZt=}Ua*Fv&{sxjc)=}TmRSYdWhZwW#+~2| zZncEx#>5rPH}!yA(QAc~m3V^(^tV8R{W!j3W?&D~M5fd0S=m^w#aXx4%EkDEn`SN! zIch+AoK`oCNJ6V?g5*7JPy@wVdT>)LRoYK#=I(GeCIYh8%D^J)3pDTKRRw*~<`3Yil^ zmB(GwAPKq1!5z0%%xP?u2gOME0*3{mL>y%9(p)c&vprGU^EFqBlk7=m+eDM`IrAOo zFU)Cy9`;w@?@URGRrrS}Lpt3SX*{GpW84n7YM8l+k{kbZps+jPhU8^oc1CL7|{yHFbQLEPaoV}cyfSd7{$C*L&#bX<+ z5Q6w`Jmzy=k}fQsSM?CC^9rkwR$b0H(N2j-kH@Zx5E7B2)jCg)G=yPVs*$edF6Z?( z)I&?b{qJKYFCwErb#awScvrA0>{mT9!phXDe}YpH)~f%-q++mEYk5(6G8Kh!<&|Q+ zOye57EcgiI#l|Nav)|S{Wh&3Z3<-5kPL=A!yrFZHJuv6t{7*P4@NW?cNyMyB$iN^+ z<^NOi`zH(uDlsHzp%xDM9OC_;7Skh4KZ=+kjMN;f8P%+0redbH=WAAL)@rWOtk>MZ z%)oA@I<6GEp=PfeJ<^NtaiUxf^*M#8WrnbWS&Am@PryQBGOq#YPG`Pm{e-8v&smNm zG{&t%rnWoj8DlF>(dXs|$e~iF2j|IWTw#79uJfzPPkeyu3~Tx11x0D0QAPQ1+(k4RA5#O3rA>y3k>Yt~5)aG7D$QnO$xT$x_Ey@UJyG$I zwUfqUKew8shdy4fpP8b=?a=kR=zz{FLA!aLO7MI05_$85TK_rXH^Hyylx|inwzvd8`(JF^~7>qM4@^FqhOmh@2u>GXACu&Z?ZT3_l z(-@BDQN>({12%}N$wui4-{ITO5{r&Z-IHcvnzBfdg>YOk2 zG5r7K#hSy(bWF2Av1qi;8rX7cg32H0TN1k(PWH;xzc0QXuG#j$cy z{sG@${)5n5VClXHlJx@FqfC#dOVGNh~glBN^kS} zl~lo7u!48^Oq5X--xZifOR<+W;~B9N2VEqU+F>~}iu$G$8qm1cz6GKLJL$T@#% zxG7bHQ<56bSrL)Un?;zZNsar+XQhT4yJIg8eax{rr+_#k_N$>Y295DWkkm9bF+!=~ z*?g~}WTj*GhCY=Q&Gbcx!mo1uaMQDbGs8`lPKYGS%Gh&7GpIYZuV`&rH-*#voT<8C z(~d}8{;A?|)ZJEJJVLa+SMsT8G(Fb+>)6UsqeCfoUm5hf?~KVCFAe_fy5^!yZGRXw G)&3tUSwtlO diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/ICrudAppService.cs b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/ICrudAppService.cs index a67aa83210..9400f8825c 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/ICrudAppService.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/ICrudAppService.cs @@ -1,15 +1,7 @@ -using System; using Volo.Abp.Application.Dtos; namespace Volo.Abp.Application.Services { - public interface ICrudAppService - : ICrudAppService - where TEntityDto : IEntityDto - { - - } - public interface ICrudAppService : ICrudAppService where TEntityDto : IEntityDto diff --git a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs index c6033714f8..97fb33377b 100644 --- a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs +++ b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -5,7 +6,7 @@ using Volo.Abp.Domain.Repositories; namespace Volo.Abp.Identity { - public interface IIdentityRoleRepository : IRepository + public interface IIdentityRoleRepository : IRepository { Task FindByNormalizedNameAsync(string normalizedRoleName, CancellationToken cancellationToken); diff --git a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs index 39b1b649bb..cc376acdc8 100644 --- a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs +++ b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs @@ -8,7 +8,7 @@ using Volo.Abp.Domain.Repositories; namespace Volo.Abp.Identity { - public interface IIdentityUserRepository : IRepository + public interface IIdentityUserRepository : IRepository { Task FindByNormalizedUserNameAsync([NotNull] string normalizedUserName, CancellationToken cancellationToken); diff --git a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs index d7054c95e5..fe6af2e7f6 100644 --- a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs +++ b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs @@ -11,7 +11,7 @@ namespace Volo.Abp.Identity /// /// Represents a role in the identity system /// - public class IdentityRole : AggregateRoot, IHasConcurrencyStamp + public class IdentityRole : AggregateRoot, IHasConcurrencyStamp { /// /// Gets or sets the name for this role. diff --git a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleClaim.cs b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleClaim.cs index d9860bff28..ec659f3f03 100644 --- a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleClaim.cs +++ b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleClaim.cs @@ -8,7 +8,7 @@ namespace Volo.Abp.Identity /// /// Represents a claim that is granted to all users within a role. /// - public class IdentityRoleClaim : Entity + public class IdentityRoleClaim : Entity { /// /// Gets or sets the of the primary key of the role associated with this claim. diff --git a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs index fe039d2b00..4e3b7097ec 100644 --- a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs +++ b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs @@ -12,7 +12,7 @@ namespace Volo.Abp.Identity { //Add Name and Surname properties? - public class IdentityUser : AggregateRoot, IHasConcurrencyStamp + public class IdentityUser : AggregateRoot, IHasConcurrencyStamp { /// /// Gets or sets the user name for this user. diff --git a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserClaim.cs b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserClaim.cs index e505db833e..4129034547 100644 --- a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserClaim.cs +++ b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserClaim.cs @@ -8,7 +8,7 @@ namespace Volo.Abp.Identity /// /// Represents a claim that a user possesses. /// - public class IdentityUserClaim : Entity + public class IdentityUserClaim : Entity { /// /// Gets or sets the primary key of the user associated with this claim. diff --git a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserLogin.cs b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserLogin.cs index f4263445c3..8556fee9d7 100644 --- a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserLogin.cs +++ b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserLogin.cs @@ -8,7 +8,7 @@ namespace Volo.Abp.Identity /// /// Represents a login and its associated provider for a user. /// - public class IdentityUserLogin : Entity + public class IdentityUserLogin : Entity { /// /// Gets or sets the of the primary key of the user associated with this login. diff --git a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRole.cs b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRole.cs index 1867ec582e..2740b67323 100644 --- a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRole.cs +++ b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRole.cs @@ -6,7 +6,7 @@ namespace Volo.Abp.Identity /// /// Represents the link between a user and a role. /// - public class IdentityUserRole : Entity + public class IdentityUserRole : Entity { /// /// Gets or sets the primary key of the user that is linked to a role. diff --git a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserToken.cs b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserToken.cs index 2e1ed4d302..e37c5b9d43 100644 --- a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserToken.cs +++ b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserToken.cs @@ -7,7 +7,7 @@ namespace Volo.Abp.Identity /// /// Represents an authentication token for a user. /// - public class IdentityUserToken : Entity + public class IdentityUserToken : Entity { /// /// Gets or sets the primary key of the user that the token belongs to. diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs index 7ab50948e8..2a6c6db2bb 100644 --- a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs @@ -11,7 +11,7 @@ using System; namespace Volo.Abp.Identity { - public class EfCoreIdentityRoleRepository : EfCoreRepository, IIdentityRoleRepository + public class EfCoreIdentityRoleRepository : EfCoreRepository, IIdentityRoleRepository { public EfCoreIdentityRoleRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs index 8deac6bef1..3b33b65390 100644 --- a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs @@ -12,7 +12,7 @@ using Volo.Abp.Identity.EntityFrameworkCore; namespace Volo.Abp.Identity { - public class EfCoreIdentityUserRepository : EfCoreRepository, IIdentityUserRepository + public class EfCoreIdentityUserRepository : EfCoreRepository, IIdentityUserRepository { public EfCoreIdentityUserRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResource.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResource.cs index 2bd9339c13..73eb194e5f 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResource.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResource.cs @@ -5,7 +5,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.ApiResources { - public class ApiResource : AggregateRoot + public class ApiResource : AggregateRoot { public virtual bool Enabled { get; set; } diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScope.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScope.cs index ab4056d657..9512190497 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScope.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScope.cs @@ -4,7 +4,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.ApiResources { - public class ApiScope : Entity + public class ApiScope : Entity { public virtual string Name { get; set; } diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs index 759bbbdf02..1ae0e26295 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs @@ -1,8 +1,9 @@ -using Volo.Abp.Domain.Repositories; +using System; +using Volo.Abp.Domain.Repositories; namespace Volo.Abp.IdentityServer.ApiResources { - public interface IApiResourceRepository : IRepository + public interface IApiResourceRepository : IRepository { } diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs index 17b35d1a05..2154495e18 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs @@ -8,7 +8,7 @@ using Volo.Abp.Guids; namespace Volo.Abp.IdentityServer.Clients { - public class Client : AggregateRoot + public class Client : AggregateRoot { public virtual string ClientId { get; set; } diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs index bb0cb7e0f5..ef1330d412 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs @@ -3,7 +3,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Clients { - public class ClientClaim : Entity + public class ClientClaim : Entity { public virtual string Type { get; set; } diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs index 4decc3132e..91d55c3348 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs @@ -3,7 +3,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Clients { - public class ClientCorsOrigin : Entity + public class ClientCorsOrigin : Entity { public virtual string Origin { get; set; } diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs index 936dc71042..9515d1fb88 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs @@ -3,7 +3,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Clients { - public class ClientIdPRestriction : Entity + public class ClientIdPRestriction : Entity { public virtual string Provider { get; set; } diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs index fa30e00819..a1e0230f2a 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs @@ -3,7 +3,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Clients { - public class ClientPostLogoutRedirectUri : Entity + public class ClientPostLogoutRedirectUri : Entity { public virtual string PostLogoutRedirectUri { get; set; } diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs index 843884cf3b..da6174d366 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs @@ -3,7 +3,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Clients { - public class ClientProperty : Entity + public class ClientProperty : Entity { public virtual string Key { get; set; } diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs index 689d15a681..073aae7c48 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs @@ -3,7 +3,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Clients { - public class ClientRedirectUri : Entity + public class ClientRedirectUri : Entity { public virtual string RedirectUri { get; set; } diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientScope.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientScope.cs index e28d33cacb..07e038ca5e 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientScope.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientScope.cs @@ -3,7 +3,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Clients { - public class ClientScope : Entity + public class ClientScope : Entity { public virtual string Scope { get; protected set; } diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/IClientRepository.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/IClientRepository.cs index c8cd46af63..d0c54dffd1 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/IClientRepository.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/IClientRepository.cs @@ -1,10 +1,11 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; using JetBrains.Annotations; using Volo.Abp.Domain.Repositories; namespace Volo.Abp.IdentityServer.Clients { - public interface IClientRepository : IRepository + public interface IClientRepository : IRepository { Task FindByCliendIdIncludingAllAsync([NotNull] string clientId); } diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/IPersistentGrantRepository.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/IPersistentGrantRepository.cs index 709fe00d62..53059b4ce9 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/IPersistentGrantRepository.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/IPersistentGrantRepository.cs @@ -1,10 +1,11 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; namespace Volo.Abp.IdentityServer.Grants { - public interface IPersistentGrantRepository : IRepository + public interface IPersistentGrantRepository : IRepository { Task FindByKeyAsync(string key); diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrant.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrant.cs index e47401d607..4a2bccd456 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrant.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrant.cs @@ -3,7 +3,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Grants { - public class PersistedGrant : AggregateRoot + public class PersistedGrant : AggregateRoot { public virtual string Key { get; set; } diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrantStore.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrantStore.cs index f312132900..31ab551053 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrantStore.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrantStore.cs @@ -1,10 +1,8 @@ using System.Collections.Generic; using System.Linq; -using System.Linq.Dynamic.Core; using System.Threading.Tasks; using IdentityServer4.Stores; using Volo.Abp.DependencyInjection; -using Volo.Abp.Domain.Repositories; using Volo.Abp.ObjectMapping; namespace Volo.Abp.IdentityServer.Grants diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceRepository.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceRepository.cs index 94b86754da..1312daa1a0 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceRepository.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceRepository.cs @@ -1,11 +1,12 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; using ApiResource = Volo.Abp.IdentityServer.ApiResources.ApiResource; namespace Volo.Abp.IdentityServer.IdentityResources { - public interface IIdentityResourceRepository : IRepository + public interface IIdentityResourceRepository : IRepository { Task> FindIdentityResourcesByScopeAsync(string[] scopeNames); diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs index 9251862c96..04dcd847ca 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs @@ -4,7 +4,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.IdentityResources { - public class IdentityResource : AggregateRoot + public class IdentityResource : AggregateRoot { public virtual bool Enabled { get; set; } = true; diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Secret.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Secret.cs index 6e7f753124..45302a97f8 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Secret.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Secret.cs @@ -6,7 +6,7 @@ namespace Volo.Abp.IdentityServer { //TODO: Eleminate Secret class for simplicity. - public abstract class Secret : Entity + public abstract class Secret : Entity { public virtual string Description { get; protected set; } diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/UserClaim.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/UserClaim.cs index 9529a42ed1..f6d911d547 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/UserClaim.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/UserClaim.cs @@ -5,7 +5,7 @@ namespace Volo.Abp.IdentityServer { //TODO: Eleminate UserClaim class for simplicity. - public abstract class UserClaim : Entity + public abstract class UserClaim : Entity { public virtual string Type { get; set; } diff --git a/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResourceRepository.cs b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResourceRepository.cs index bd62b96b6b..359930e2e4 100644 --- a/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResourceRepository.cs +++ b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResourceRepository.cs @@ -1,11 +1,12 @@ -using Volo.Abp.Domain.Repositories.EntityFrameworkCore; +using System; +using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.IdentityServer.ApiResources; using Volo.Abp.IdentityServer.EntityFrameworkCore; namespace Volo.Abp.IdentityServer { - public class ApiResourceRepository : EfCoreRepository, IApiResourceRepository + public class ApiResourceRepository : EfCoreRepository, IApiResourceRepository { public ApiResourceRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) { diff --git a/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ClientRepository.cs b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ClientRepository.cs index e0d44d2183..da142e91e9 100644 --- a/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ClientRepository.cs +++ b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ClientRepository.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; @@ -7,7 +8,7 @@ using Volo.Abp.IdentityServer.EntityFrameworkCore; namespace Volo.Abp.IdentityServer { - public class ClientRepository : EfCoreRepository, IClientRepository + public class ClientRepository : EfCoreRepository, IClientRepository { public ClientRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) { diff --git a/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResourceRepository.cs b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResourceRepository.cs index ff49b87a8e..80659d6f28 100644 --- a/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResourceRepository.cs +++ b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResourceRepository.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; @@ -13,7 +14,7 @@ namespace Volo.Abp.IdentityServer { //TODO: This is not true implementation! This repository works for 2 different aggregate root! - public class IdentityResourceRepository : EfCoreRepository, IIdentityResourceRepository + public class IdentityResourceRepository : EfCoreRepository, IIdentityResourceRepository { public IdentityResourceRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) diff --git a/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/PersistedGrantRepository.cs b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/PersistedGrantRepository.cs index 0b1011992c..999192a27c 100644 --- a/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/PersistedGrantRepository.cs +++ b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/PersistedGrantRepository.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; @@ -9,7 +10,7 @@ using Volo.Abp.IdentityServer.Grants; namespace Volo.Abp.IdentityServer { - public class PersistentGrantRepository : EfCoreRepository, IPersistentGrantRepository + public class PersistentGrantRepository : EfCoreRepository, IPersistentGrantRepository { public PersistentGrantRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) { diff --git a/src/Volo.Abp.MultiTenancy.Domain/Volo/Abp/MultiTenancy/ITenantRepository.cs b/src/Volo.Abp.MultiTenancy.Domain/Volo/Abp/MultiTenancy/ITenantRepository.cs index d8486c8ae6..563cf8dc0d 100644 --- a/src/Volo.Abp.MultiTenancy.Domain/Volo/Abp/MultiTenancy/ITenantRepository.cs +++ b/src/Volo.Abp.MultiTenancy.Domain/Volo/Abp/MultiTenancy/ITenantRepository.cs @@ -4,7 +4,7 @@ using Volo.Abp.Domain.Repositories; namespace Volo.Abp.MultiTenancy { - public interface ITenantRepository : IRepository + public interface ITenantRepository : IRepository { Task FindByNameIncludeDetailsAsync(string name); diff --git a/src/Volo.Abp.MultiTenancy.Domain/Volo/Abp/MultiTenancy/Tenant.cs b/src/Volo.Abp.MultiTenancy.Domain/Volo/Abp/MultiTenancy/Tenant.cs index 4a572526c5..4c6d4feac4 100644 --- a/src/Volo.Abp.MultiTenancy.Domain/Volo/Abp/MultiTenancy/Tenant.cs +++ b/src/Volo.Abp.MultiTenancy.Domain/Volo/Abp/MultiTenancy/Tenant.cs @@ -6,7 +6,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.MultiTenancy { - public class Tenant : AggregateRoot + public class Tenant : AggregateRoot { public virtual string Name { get; protected set; } diff --git a/src/Volo.Abp.MultiTenancy.Domain/Volo/Abp/MultiTenancy/TenantConnectionString.cs b/src/Volo.Abp.MultiTenancy.Domain/Volo/Abp/MultiTenancy/TenantConnectionString.cs index 2d3c5235e1..c65163aaac 100644 --- a/src/Volo.Abp.MultiTenancy.Domain/Volo/Abp/MultiTenancy/TenantConnectionString.cs +++ b/src/Volo.Abp.MultiTenancy.Domain/Volo/Abp/MultiTenancy/TenantConnectionString.cs @@ -4,7 +4,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.MultiTenancy { - public class TenantConnectionString : Entity //TODO: This should be a value object! + public class TenantConnectionString : Entity //TODO: PK should be TenantId + Name (so, inherit from Entity) { public virtual Guid TenantId { get; protected set; } diff --git a/src/Volo.Abp.MultiTenancy.EntityFrameworkCore/Volo/Abp/MultiTenancy/EfCoreTenantRepository.cs b/src/Volo.Abp.MultiTenancy.EntityFrameworkCore/Volo/Abp/MultiTenancy/EfCoreTenantRepository.cs index 66b6ed0fa3..6b52af0d1d 100644 --- a/src/Volo.Abp.MultiTenancy.EntityFrameworkCore/Volo/Abp/MultiTenancy/EfCoreTenantRepository.cs +++ b/src/Volo.Abp.MultiTenancy.EntityFrameworkCore/Volo/Abp/MultiTenancy/EfCoreTenantRepository.cs @@ -7,7 +7,7 @@ using Volo.Abp.MultiTenancy.EntityFrameworkCore; namespace Volo.Abp.MultiTenancy { - public class EfCoreTenantRepository : EfCoreRepository, ITenantRepository + public class EfCoreTenantRepository : EfCoreRepository, ITenantRepository { public EfCoreTenantRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) diff --git a/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntity.cs b/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntity.cs index 0a0b2f6bf4..8f24cb0966 100644 --- a/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntity.cs +++ b/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntity.cs @@ -1,8 +1,9 @@ -using Volo.Abp.Domain.Entities; +using System; +using Volo.Abp.Domain.Entities; namespace Volo.Abp.AutoMapper.SampleClasses { - public class MyEntity : Entity + public class MyEntity : Entity { public int Number { get; set; } } diff --git a/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs b/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs index fbbbc0c77c..8a0f7ae652 100644 --- a/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs +++ b/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using Microsoft.Extensions.DependencyInjection; -using Volo.Abp.Data; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Entities; using Xunit; @@ -127,7 +126,7 @@ namespace Volo.Abp.Domain.Repositories public class MyFakeDbContext { } - public class MyTestAggregateRootWithDefaultPk : AggregateRoot + public class MyTestAggregateRootWithDefaultPk : AggregateRoot { } @@ -137,7 +136,7 @@ namespace Volo.Abp.Domain.Repositories } - public class MyTestDefaultRepository : MyTestDefaultRepository, IRepository + public class MyTestDefaultRepository : MyTestDefaultRepository where TEntity : class, IEntity { @@ -182,7 +181,7 @@ namespace Volo.Abp.Domain.Repositories } - public class MyTestCustomBaseRepository : MyTestCustomBaseRepository, IRepository + public class MyTestCustomBaseRepository : MyTestCustomBaseRepository where TEntity : class, IEntity { diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/BookInSecondDbContext.cs b/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/BookInSecondDbContext.cs index 61bc73b5ec..0e22533c11 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/BookInSecondDbContext.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/BookInSecondDbContext.cs @@ -1,8 +1,9 @@ -using Volo.Abp.Domain.Entities; +using System; +using Volo.Abp.Domain.Entities; namespace Volo.Abp.EntityFrameworkCore.TestApp.SecondContext { - public class BookInSecondDbContext : AggregateRoot + public class BookInSecondDbContext : AggregateRoot { public string Name { get; set; } } diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/SecondContextTestDataBuilder.cs b/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/SecondContextTestDataBuilder.cs index 1beb893d17..5e7658706c 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/SecondContextTestDataBuilder.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/SecondContextTestDataBuilder.cs @@ -1,4 +1,5 @@ -using Volo.Abp.DependencyInjection; +using System; +using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Repositories; using Volo.Abp.Guids; @@ -6,10 +7,10 @@ namespace Volo.Abp.EntityFrameworkCore.TestApp.SecondContext { public class SecondContextTestDataBuilder : ITransientDependency { - private readonly IRepository _bookRepository; + private readonly IRepository _bookRepository; private readonly IGuidGenerator _guidGenerator; - public SecondContextTestDataBuilder(IRepository bookRepository, IGuidGenerator guidGenerator) + public SecondContextTestDataBuilder(IRepository bookRepository, IGuidGenerator guidGenerator) { _bookRepository = bookRepository; _guidGenerator = guidGenerator; diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/ThirdDbContext/ThirdDbContextDummyEntity.cs b/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/ThirdDbContext/ThirdDbContextDummyEntity.cs index f88dfc2cb8..bcb1cf65b7 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/ThirdDbContext/ThirdDbContextDummyEntity.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/ThirdDbContext/ThirdDbContextDummyEntity.cs @@ -1,8 +1,9 @@ -using Volo.Abp.Domain.Entities; +using System; +using Volo.Abp.Domain.Entities; namespace Volo.Abp.EntityFrameworkCore.TestApp.ThirdDbContext { - public class ThirdDbContextDummyEntity : AggregateRoot + public class ThirdDbContextDummyEntity : AggregateRoot { public string Value { get; set; } } diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/MultiTenant_Filter_Tests.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/MultiTenant_Filter_Tests.cs index ab9dda2e72..6fe033ebce 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/MultiTenant_Filter_Tests.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/MultiTenant_Filter_Tests.cs @@ -17,12 +17,12 @@ namespace Volo.Abp.EntityFrameworkCore.DataFiltering public class MultiTenant_Filter_Tests : EntityFrameworkCoreTestBase { private ICurrentTenant _fakeCurrentTenant; - private readonly IRepository _personRepository; + private readonly IRepository _personRepository; private readonly IDataFilter _multiTenantFilter; public MultiTenant_Filter_Tests() { - _personRepository = GetRequiredService>(); + _personRepository = GetRequiredService>(); _multiTenantFilter = GetRequiredService>(); } diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/SoftDelete_Filter_Tests.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/SoftDelete_Filter_Tests.cs index ba28f82b5c..fd087a4268 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/SoftDelete_Filter_Tests.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/SoftDelete_Filter_Tests.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using Shouldly; using Volo.Abp.Data; using Volo.Abp.Domain.Repositories; @@ -9,12 +10,12 @@ namespace Volo.Abp.EntityFrameworkCore.DataFiltering { public class SoftDelete_Filter_Tests : EntityFrameworkCoreTestBase { - private readonly IRepository _personRepository; + private readonly IRepository _personRepository; private readonly IDataFilter _dataFilter; public SoftDelete_Filter_Tests() { - _personRepository = GetRequiredService>(); + _personRepository = GetRequiredService>(); _dataFilter = GetRequiredService(); } diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DbContext_Replace_Tests.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DbContext_Replace_Tests.cs index a86797feed..755ea0b3f7 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DbContext_Replace_Tests.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DbContext_Replace_Tests.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.DependencyInjection; +using System; +using Microsoft.Extensions.DependencyInjection; using Shouldly; using Volo.Abp.Domain.Repositories; using Volo.Abp.EntityFrameworkCore.TestApp.ThirdDbContext; @@ -9,11 +10,11 @@ namespace Volo.Abp.EntityFrameworkCore { public class DbContext_Replace_Tests : EntityFrameworkCoreTestBase { - private readonly IRepository _dummyRepository; + private readonly IRepository _dummyRepository; public DbContext_Replace_Tests() { - _dummyRepository = ServiceProvider.GetRequiredService>(); + _dummyRepository = ServiceProvider.GetRequiredService>(); } [Fact] diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Basic_Repository_Tests.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Basic_Repository_Tests.cs index 3c2edb33f9..55f35f94da 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Basic_Repository_Tests.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Basic_Repository_Tests.cs @@ -12,14 +12,14 @@ namespace Volo.Abp.EntityFrameworkCore.Repositories { public class Basic_Repository_Tests : EntityFrameworkCoreTestBase { - private readonly IRepository _personRepository; - private readonly IRepository _bookRepository; + private readonly IRepository _personRepository; + private readonly IRepository _bookRepository; private readonly IRepository _phoneInSecondDbContextRepository; public Basic_Repository_Tests() { - _personRepository = ServiceProvider.GetRequiredService>(); - _bookRepository = ServiceProvider.GetRequiredService>(); + _personRepository = ServiceProvider.GetRequiredService>(); + _bookRepository = ServiceProvider.GetRequiredService>(); _phoneInSecondDbContextRepository = ServiceProvider.GetRequiredService>(); } diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Transaction_Tests.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Transaction_Tests.cs index 572b4efc3f..58fe4b0a38 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Transaction_Tests.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Transaction_Tests.cs @@ -12,14 +12,14 @@ namespace Volo.Abp.EntityFrameworkCore { public class Transaction_Tests : EntityFrameworkCoreTestBase { - private readonly IRepository _personRepository; - private readonly IRepository _bookRepository; + private readonly IRepository _personRepository; + private readonly IRepository _bookRepository; private readonly IUnitOfWorkManager _unitOfWorkManager; public Transaction_Tests() { - _personRepository = ServiceProvider.GetRequiredService>(); - _bookRepository = ServiceProvider.GetRequiredService>(); + _personRepository = ServiceProvider.GetRequiredService>(); + _bookRepository = ServiceProvider.GetRequiredService>(); _unitOfWorkManager = ServiceProvider.GetRequiredService(); } diff --git a/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs b/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs index e4af66fa62..71fa487415 100644 --- a/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs +++ b/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs @@ -15,12 +15,12 @@ namespace Volo.Abp.Http.DynamicProxying public class PersonAppServiceClientProxy_Tests : AbpHttpTestBase { private readonly IPeopleAppService _peopleAppService; - private readonly IRepository _personRepository; + private readonly IRepository _personRepository; public PersonAppServiceClientProxy_Tests() { _peopleAppService = ServiceProvider.GetRequiredService(); - _personRepository = ServiceProvider.GetRequiredService>(); + _personRepository = ServiceProvider.GetRequiredService>(); } [Fact] diff --git a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MultiTenant_Filter_Tests.cs b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MultiTenant_Filter_Tests.cs index 33d79461e4..e3c5c5fc24 100644 --- a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MultiTenant_Filter_Tests.cs +++ b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MultiTenant_Filter_Tests.cs @@ -17,12 +17,12 @@ namespace Volo.Abp.MemoryDb.DataFilters public class MemoryDb_MultiTenant_Filter_Tests : MemoryDbTestBase { private ICurrentTenant _fakeCurrentTenant; - private readonly IRepository _personRepository; + private readonly IRepository _personRepository; private readonly IDataFilter _multiTenantFilter; public MemoryDb_MultiTenant_Filter_Tests() { - _personRepository = GetRequiredService>(); + _personRepository = GetRequiredService>(); _multiTenantFilter = GetRequiredService>(); } diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs index 6f91db9c30..553ca30abd 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs @@ -5,7 +5,7 @@ using Volo.Abp.MultiTenancy; namespace Volo.Abp.TestApp.Domain { - public class Person : AggregateRoot, IMultiTenant, ISoftDelete + public class Person : AggregateRoot, IMultiTenant, ISoftDelete { public virtual Guid? TenantId { get; set; } diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs index 80e6e8e2a7..a87691ffe8 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs @@ -10,9 +10,9 @@ namespace Volo.Abp.TestApp public static Guid TenantId1 { get; } = new Guid("55687dce-595c-41b4-a024-2a5e991ac8f4"); public static Guid TenantId2 { get; } = new Guid("f522d19f-5a86-4278-98fb-0577319c544a"); - private readonly IRepository _personRepository; + private readonly IRepository _personRepository; - public TestDataBuilder(IRepository personRepository) + public TestDataBuilder(IRepository personRepository) { _personRepository = personRepository; } From f66ca10231c0f45b214c0b8e6dbebb43d8419069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 25 Jan 2018 09:28:46 +0300 Subject: [PATCH 03/14] Temporary remove default PK entity, repository, agg root etc. --- .../AbpDesk/ConsoleDemo/BlogPostLister.cs | 4 +- .../AbpDesk/ConsoleDemo/UserLister.cs | 4 +- .../Blogging/AbpDeskMongoBlogModule.cs | 5 +- .../Areas/Blog/Controllers/PostsController.cs | 7 +- src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll | Bin 15360 -> 15360 bytes .../ServiceCollectionRepositoryExtensions.cs | 50 +++++++-------- .../Services/CrudAppServiceBase.cs | 1 - .../Services/IAsyncCrudAppService.cs | 8 --- .../CommonDbContextRegistrationOptions.cs | 8 +-- ...mmonDbContextRegistrationOptionsBuilder.cs | 3 +- .../Volo/Abp/Domain/Entities/AggregateRoot.cs | 6 +- .../Volo/Abp/Domain/Entities/Entity.cs | 12 ++-- .../Abp/Domain/Entities/IAggregateRoot.cs | 6 +- .../Volo/Abp/Domain/Entities/IEntity.cs | 12 ++-- .../Repositories/IQueryableRepository.cs | 8 +-- .../Abp/Domain/Repositories/IRepository.cs | 8 +-- .../Repositories/QueryableRepositoryBase.cs | 8 +-- .../Abp/Domain/Repositories/RepositoryBase.cs | 8 +-- .../Repositories/RepositoryRegistrarBase.cs | 18 +++--- .../EntityFrameworkCore/EfCoreRepository.cs | 18 +++--- .../EntityFrameworkCore/IEfCoreRepository.cs | 8 +-- .../EfCoreRepositoryRegistrar.cs | 8 +-- .../MemoryDb/IMemoryDbRepository.cs | 8 +-- .../MemoryDb/MemoryDbRepository.cs | 18 +++--- .../MemoryDbRepositoryRegistrar.cs | 5 -- .../MongoDB/IMongoDbRepository.cs | 8 +-- .../Repositories/MongoDB/MongoDbRepository.cs | 18 +++--- .../MongoDbRepositoryRegistrar.cs | 5 -- .../AspNetCore/Mvc/PersonAppService_Tests.cs | 4 +- .../RepositoryRegistration_Tests.cs | 60 ++++++++---------- .../Volo/Abp/Identity/Initialize_Tests.cs | 4 +- .../MemoryDb_SoftDelete_DataFilter_Tests.cs | 7 +- .../MemoryDb_Basic_Repository_Tests.cs | 4 +- .../TestApp/Application/IPeopleAppService.cs | 2 +- .../TestApp/Application/PeopleAppService.cs | 2 +- 35 files changed, 166 insertions(+), 189 deletions(-) diff --git a/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/BlogPostLister.cs b/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/BlogPostLister.cs index 5d664d7a0d..c0bf2e9556 100644 --- a/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/BlogPostLister.cs +++ b/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/BlogPostLister.cs @@ -9,11 +9,11 @@ namespace AbpDesk.ConsoleDemo { public class BlogPostLister : ITransientDependency { - private readonly IQueryableRepository _blogPostRepository; + private readonly IQueryableRepository _blogPostRepository; private readonly IGuidGenerator _guidGenerator; public BlogPostLister( - IQueryableRepository blogPostRepository, + IQueryableRepository blogPostRepository, IGuidGenerator guidGenerator) { _blogPostRepository = blogPostRepository; diff --git a/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/UserLister.cs b/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/UserLister.cs index 51a5a8f1e0..46b038c511 100644 --- a/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/UserLister.cs +++ b/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/UserLister.cs @@ -11,11 +11,11 @@ namespace AbpDesk.ConsoleDemo public class UserLister : ITransientDependency { private readonly IdentityUserManager _userManager; - private readonly IQueryableRepository _userRepository; + private readonly IQueryableRepository _userRepository; public UserLister( IdentityUserManager userManager, - IQueryableRepository userRepository) + IQueryableRepository userRepository) { _userManager = userManager; _userRepository = userRepository; diff --git a/src/AbpDesk/AbpDesk.MongoBlog/AbpDesk/Blogging/AbpDeskMongoBlogModule.cs b/src/AbpDesk/AbpDesk.MongoBlog/AbpDesk/Blogging/AbpDeskMongoBlogModule.cs index 8e5df159d1..90e0b6b1cc 100644 --- a/src/AbpDesk/AbpDesk.MongoBlog/AbpDesk/Blogging/AbpDeskMongoBlogModule.cs +++ b/src/AbpDesk/AbpDesk.MongoBlog/AbpDesk/Blogging/AbpDeskMongoBlogModule.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Volo.Abp; @@ -46,7 +47,7 @@ namespace AbpDesk.Blogging using (var uow = scope.ServiceProvider.GetRequiredService().Begin()) { - var blogPostRepository = scope.ServiceProvider.GetRequiredService>(); + var blogPostRepository = scope.ServiceProvider.GetRequiredService>(); if (blogPostRepository.Any()) { logger.LogInformation($"No need to seed database since there are already {blogPostRepository.Count()} blog posts!"); diff --git a/src/AbpDesk/AbpDesk.MongoBlog/Areas/Blog/Controllers/PostsController.cs b/src/AbpDesk/AbpDesk.MongoBlog/Areas/Blog/Controllers/PostsController.cs index 64e0dcf640..ec761ebfe4 100644 --- a/src/AbpDesk/AbpDesk.MongoBlog/Areas/Blog/Controllers/PostsController.cs +++ b/src/AbpDesk/AbpDesk.MongoBlog/Areas/Blog/Controllers/PostsController.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; using AbpDesk.Blogging; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc; @@ -9,9 +10,9 @@ namespace Areas.Blog.Controllers [Area("Blog")] public class PostsController : AbpController { - private readonly IQueryableRepository _blogPostRepository; + private readonly IQueryableRepository _blogPostRepository; - public PostsController(IQueryableRepository blogPostRepository) + public PostsController(IQueryableRepository blogPostRepository) { _blogPostRepository = blogPostRepository; } diff --git a/src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll b/src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll index a6bb0c90e4f934c925e089b4398fc610bba4a6ab..e18ffa8870111b6acf25bcd5eff6e366b5f589de 100644 GIT binary patch delta 2142 zcmY*aYitx%6#mYg*_qwh?sR9iqs4BQDHU1@)YgKa@+bjP3#ourkPxh-8f*$Cq*O%{ zcUFkO2hnP@sfvh+KYS%%G}5Rsh>4&vzQuFz7LAkLZ@%;0^SJli zJ2TN;(Or-3FrOUG{W|b)mhKzax0)`KM0K(4D}gz3^UUdT4b{;OS)e?1OA;A>%cTIJ zbiKF~IAO6{Lve+8L{L-llo=Y7lN5h~K9NK5uN;rwb1dYU{wahIHn4d8|m-vElUGf{& z+i;rkPmP^8C$2y}{Ut8CmZw9;MYt46V@0T1aDS!c1P0-jl7&NVjUn)&w%$dT)4*1$ zMtQ!A8S!SrK&7?@a6QeD)5@x<7Z@>oJV|+|Toz*ZTw4Q`WzJIBUAAP}wT6v`TIKOh zVmNgpTP@n!uKnX^)s~9xmLHd`FYh&6*t|)~KbP1d7o}#?z4D&a5?U%pQ&r^;83CqD zQRCY%1CPlwsRwA2?00X-55saU!9GR{$2Fcrqif+LzB5AnrWKDYX9_kmrZLPo3k9ub z(Pyqg7BRPr@qT+Fcgb?@#Q~b_ZpU=ZN9j8ASsbS?t%I0K^Ag|VBn9S=j30?V_#m{G zCzm&CokV4PDka2E?tI4cspV87MpA33o%+lTG!sep4qA+3w38OnQ>KMx(aSi2=VM{3 z#v#lwo~DA_Q{F)z%5&vy)FZD<*W_O@8j-;P#wwg(ti>4PG>t9zmig71FVeUSf3wnw zdb1I0(Z$$}jf}nQ*@}B`r`gI~eA!%tJ{&f?@dA#S1w6z`0SED#xeY}ej16mLSSfjP zR2!pucuey#&A-x|NCgwAU_iRT%A7DMuY*PWP)<><#Q zY%EUpm(c28Md=-J%m&WJN_g0bL)>AL`(@rcCyKq#FX15!j| zhY0*Ntj0O;CGw+JW1*mIrI#k*M+5x3pey$@d*!v;Nc#T{ImCE88cC#iZaPl+m(|#| z9}RJe-E8>LaNsWyeudZWM|(x!Mf)fg3*kqn}HUWd= z&vjmU*pL1aj&dpGlNI&#H|{kZk9Jvm+=fAX8m?Xb2 zFROQct6VU3c|O52E3I8vZp^CYb;McHE40T~EUdVq>JS)~uehFOlC=xDSr1jJ(%%2e zMv~m53kAl{2%jVtd2`i`BObS)%*P#dgi4*1xrPbLZ2m-g?XIhrs2ZP8{(1|_LX%wA zEg7Y3ua<5jMm^j_y~?EaD9(%{irX3{i;MXS1^jUE&Hlcg+c$)rTl==$y6NhaQ+#>) zHI$ehw)OYiGC%B+1C4}w+subR7>9_&o+3;*b9!S!k(E z|2=!c*vd!jMT2W@sJru=aZ0|{(v@0$o%(o`uFW!>Sw-E&xij}u(Y@k#Lu|ji=w0;# I4K&&R0PQHgMgRZ+ delta 2132 zcmY*a3v3is6g~IN?9A@8JKde_k}BI}m(udDV9QS=mLM&aAe29%fm*9H;HQ+TNaD__ zX*5c3^8$)m(~1xYl2|vQhXI_{{jjpsW+a9izuQ{D1k3qoTnIdR(huZt)w4%z4%@enx2*Y5cBWTf96vL6m z@9sXa)IVq(5)%KBA-#UaL5G;R|E%ol0irqLJ2S*c)dA!nXo+!gwQ@s^@4ww-qeB<(3-)FKg>vta7T@3a6Fl zyBHrFZx|@kRt}4)R*o$mT0Y$f;M3vCL*=p%z$tCz%8H$O*-|`v>_OThwx+6COh3FneDKgE78knpj1lxQPDWPi33Qmt zkwCz0X6&->;x1W^kNq^o?ZPmbrJBlIIqQr!H7@e^?gXJuna(frX` zCs7t0O(Ai?y_WHEcpjz2YvC0%lRC^+szs4|FI|rT+Dy~vIn%;Kv6eB)^;l@vn8SGE zdDEUYL?R?>C9fE8Zqo+9E#5vD{z`|ti~FA#eBNvvoy}dB~})p(yYcx z+|1a5HpaE=S%*#7VAgRLUp8l<18niJ-=7PqyA0`1XA$)?}Ff%t%`7TQYj&a z27{~!p*#u0p+pD<$%`YSZnx+EC4$ODWs^fjjk>9qGpS|Ay=+`~rA+OVi1FzVynHp2 z&G|kfuS~Ts2FF(U`+3@fHc#Fd&6ZodZm-eh5=0V7xICk4#l3d9ZPc)gD%IuphA>l{ zGXQeS-IyH+dMo15J2_RmT2;d9RO`u3RJCL$m85uJi5`q8n`qolIw7L{!446ipa~(Na&sKl-G@(pRu_zwRT~-0jr!>5oAHHk4N-+g%wm(JphK~ zDXxnwV(p*ItfxXMPVf7_tS`hZDx@ELI`|o4iMO?I%UR7(X3kL$Poax^eki0()nrF! z(DelQ8_K)kx_ZrOCv@Ta~ - var repositoryInterfaceWithDefaultPrimaryKey = typeof(IRepository<>).MakeGenericType(entityType); - if (!repositoryInterfaceWithDefaultPrimaryKey.GetTypeInfo().IsAssignableFrom(repositoryImplementationType)) - { - throw new AbpException($"Given repositoryImplementationType ({repositoryImplementationType}) must implement {repositoryInterfaceWithDefaultPrimaryKey}"); - } + //private static void AddDefaultRepositoryForDefaultPrimaryKey(IServiceCollection services, Type entityType, Type repositoryImplementationType) + //{ + // //IRepository + // var repositoryInterfaceWithDefaultPrimaryKey = typeof(IRepository<>).MakeGenericType(entityType); + // if (!repositoryInterfaceWithDefaultPrimaryKey.GetTypeInfo().IsAssignableFrom(repositoryImplementationType)) + // { + // throw new AbpException($"Given repositoryImplementationType ({repositoryImplementationType}) must implement {repositoryInterfaceWithDefaultPrimaryKey}"); + // } - services.TryAddTransient(repositoryInterfaceWithDefaultPrimaryKey, repositoryImplementationType); + // services.TryAddTransient(repositoryInterfaceWithDefaultPrimaryKey, repositoryImplementationType); - //IQueryableRepository - var queryableRepositoryInterfaceWithDefaultPrimaryKey = typeof(IQueryableRepository<>).MakeGenericType(entityType); - if (queryableRepositoryInterfaceWithDefaultPrimaryKey.GetTypeInfo().IsAssignableFrom(repositoryImplementationType)) - { - services.TryAddTransient(queryableRepositoryInterfaceWithDefaultPrimaryKey, repositoryImplementationType); - } - } + // //IQueryableRepository + // var queryableRepositoryInterfaceWithDefaultPrimaryKey = typeof(IQueryableRepository<>).MakeGenericType(entityType); + // if (queryableRepositoryInterfaceWithDefaultPrimaryKey.GetTypeInfo().IsAssignableFrom(repositoryImplementationType)) + // { + // services.TryAddTransient(queryableRepositoryInterfaceWithDefaultPrimaryKey, repositoryImplementationType); + // } + //} - private static bool BothSupportsDefaultPrimaryKey(Type entityType, Type repositoryImplementationType) - { - return typeof(IEntity).GetTypeInfo().IsAssignableFrom(entityType) && - ReflectionHelper.IsAssignableToGenericType(repositoryImplementationType, typeof(IRepository<>)); - } + //private static bool BothSupportsDefaultPrimaryKey(Type entityType, Type repositoryImplementationType) + //{ + // return typeof(IEntity).GetTypeInfo().IsAssignableFrom(entityType) && + // ReflectionHelper.IsAssignableToGenericType(repositoryImplementationType, typeof(IRepository<>)); + //} } } \ No newline at end of file diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppServiceBase.cs b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppServiceBase.cs index 3cdff642f1..ec04a532ab 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppServiceBase.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppServiceBase.cs @@ -4,7 +4,6 @@ using System.Linq.Dynamic.Core; using Volo.Abp.Application.Dtos; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories; -using Volo.Abp.ObjectMapping; namespace Volo.Abp.Application.Services { diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/IAsyncCrudAppService.cs b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/IAsyncCrudAppService.cs index a94d0ce554..37c8293df4 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/IAsyncCrudAppService.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/IAsyncCrudAppService.cs @@ -1,16 +1,8 @@ -using System; using System.Threading.Tasks; using Volo.Abp.Application.Dtos; namespace Volo.Abp.Application.Services { - public interface IAsyncCrudAppService - : IAsyncCrudAppService - where TEntityDto : IEntityDto - { - - } - public interface IAsyncCrudAppService : IAsyncCrudAppService where TEntityDto : IEntityDto diff --git a/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/CommonDbContextRegistrationOptions.cs b/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/CommonDbContextRegistrationOptions.cs index 99f087c54d..cced597bd4 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/CommonDbContextRegistrationOptions.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/CommonDbContextRegistrationOptions.cs @@ -20,7 +20,7 @@ namespace Volo.Abp.DependencyInjection public Type DefaultRepositoryImplementationType { get; private set; } - public Type DefaultRepositoryImplementationTypeWithDefaultPrimaryKey { get; private set; } + //public Type DefaultRepositoryImplementationTypeWithDefaultPrimaryKey { get; private set; } public bool RegisterDefaultRepositories { get; private set; } @@ -28,7 +28,7 @@ namespace Volo.Abp.DependencyInjection public Dictionary CustomRepositories { get; } - public bool SpecifiedDefaultRepositoryTypes => DefaultRepositoryImplementationType != null && DefaultRepositoryImplementationTypeWithDefaultPrimaryKey != null; + public bool SpecifiedDefaultRepositoryTypes => DefaultRepositoryImplementationType != null; // && DefaultRepositoryImplementationTypeWithDefaultPrimaryKey != null; protected CommonDbContextRegistrationOptions(Type originalDbContextType) { @@ -87,13 +87,11 @@ namespace Volo.Abp.DependencyInjection return this; } - public ICommonDbContextRegistrationOptionsBuilder SetDefaultRepositoryClasses([NotNull] Type repositoryImplementationType, [NotNull] Type repositoryImplementationTypeWithDefaultPrimaryKey) + public ICommonDbContextRegistrationOptionsBuilder SetDefaultRepositoryClasses([NotNull] Type repositoryImplementationType) { Check.NotNull(repositoryImplementationType, nameof(repositoryImplementationType)); - Check.NotNull(repositoryImplementationTypeWithDefaultPrimaryKey, nameof(repositoryImplementationTypeWithDefaultPrimaryKey)); DefaultRepositoryImplementationType = repositoryImplementationType; - DefaultRepositoryImplementationTypeWithDefaultPrimaryKey = repositoryImplementationTypeWithDefaultPrimaryKey; return this; } diff --git a/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/ICommonDbContextRegistrationOptionsBuilder.cs b/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/ICommonDbContextRegistrationOptionsBuilder.cs index f15509dfbe..b78c2d7e67 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/ICommonDbContextRegistrationOptionsBuilder.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/ICommonDbContextRegistrationOptionsBuilder.cs @@ -47,9 +47,8 @@ namespace Volo.Abp.DependencyInjection /// Uses given class(es) for default repositories. /// /// Repository implementation type - /// Repository implementation type for default primary key type () /// - ICommonDbContextRegistrationOptionsBuilder SetDefaultRepositoryClasses(Type repositoryImplementationType, Type repositoryImplementationTypeWithDefaultPrimaryKey); + ICommonDbContextRegistrationOptionsBuilder SetDefaultRepositoryClasses(Type repositoryImplementationType); /// /// Replaces given DbContext type with this DbContext type. diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/AggregateRoot.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/AggregateRoot.cs index 3c8d2771f5..58940bc7af 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/AggregateRoot.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/AggregateRoot.cs @@ -2,10 +2,10 @@ namespace Volo.Abp.Domain.Entities { - public abstract class AggregateRoot : AggregateRoot, IAggregateRoot - { + //public abstract class AggregateRoot : AggregateRoot, IAggregateRoot + //{ - } + //} public abstract class AggregateRoot : Entity, IAggregateRoot { diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs index 7b09c60baa..6cc3303565 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs @@ -3,13 +3,13 @@ using System.Reflection; namespace Volo.Abp.Domain.Entities { - /// - /// A shortcut of for default primary key type (). - /// - public abstract class Entity : Entity, IEntity - { + ///// + ///// A shortcut of for default primary key type (). + ///// + //public abstract class Entity : Entity, IEntity + //{ - } + //} /// /// diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IAggregateRoot.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IAggregateRoot.cs index 9ef287eb68..adb3f11d60 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IAggregateRoot.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IAggregateRoot.cs @@ -2,10 +2,10 @@ namespace Volo.Abp.Domain.Entities { - public interface IAggregateRoot : IAggregateRoot, IEntity - { + //public interface IAggregateRoot : IAggregateRoot, IEntity + //{ - } + //} public interface IAggregateRoot : IEntity { diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs index 9534c6c38d..ff798a8253 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs @@ -2,13 +2,13 @@ namespace Volo.Abp.Domain.Entities { - /// - /// A shortcut of for default primary key type (). - /// - public interface IEntity : IEntity - { + ///// + ///// A shortcut of for default primary key type (). + ///// + //public interface IEntity : IEntity + //{ - } + //} /// /// Defines interface for base entity type. All entities in the system must implement this interface. diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IQueryableRepository.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IQueryableRepository.cs index 53e65ce336..08bb61a442 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IQueryableRepository.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IQueryableRepository.cs @@ -8,11 +8,11 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.Domain.Repositories { - public interface IQueryableRepository : IQueryableRepository, IRepository - where TEntity : class, IEntity - { + //public interface IQueryableRepository : IQueryableRepository, IRepository + // where TEntity : class, IEntity + //{ - } + //} public interface IQueryableRepository : IRepository, IQueryable where TEntity : class, IEntity diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs index 2af29b9cbc..f2bc729011 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs @@ -13,11 +13,11 @@ namespace Volo.Abp.Domain.Repositories } - public interface IRepository : IRepository - where TEntity : class, IEntity - { + //public interface IRepository : IRepository + // where TEntity : class, IEntity + //{ - } + //} public interface IRepository : IRepository where TEntity : class, IEntity diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs index d75d4b8f13..8bdc50b4b3 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs @@ -11,11 +11,11 @@ using Volo.Abp.MultiTenancy; namespace Volo.Abp.Domain.Repositories { - public abstract class QueryableRepositoryBase : QueryableRepositoryBase, IQueryableRepository - where TEntity : class, IEntity - { + //public abstract class QueryableRepositoryBase : QueryableRepositoryBase, IQueryableRepository + // where TEntity : class, IEntity + //{ - } + //} public abstract class QueryableRepositoryBase : RepositoryBase, IQueryableRepository where TEntity : class, IEntity diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs index 062d130ad0..a1c890c600 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs @@ -8,11 +8,11 @@ using Volo.Abp.Threading; namespace Volo.Abp.Domain.Repositories { - public abstract class RepositoryBase : RepositoryBase, IRepository - where TEntity : class, IEntity - { + //public abstract class RepositoryBase : RepositoryBase, IRepository + // where TEntity : class, IEntity + //{ - } + //} public abstract class RepositoryBase : IRepository where TEntity : class, IEntity diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryRegistrarBase.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryRegistrarBase.cs index ea3e1963f8..544da02f10 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryRegistrarBase.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryRegistrarBase.cs @@ -46,20 +46,22 @@ namespace Volo.Abp.Domain.Repositories protected void RegisterDefaultRepository(IServiceCollection services, Type entityType) { var primaryKeyType = EntityHelper.GetPrimaryKeyType(entityType); - var isDefaultPrimaryKey = primaryKeyType == typeof(Guid); + //var isDefaultPrimaryKey = primaryKeyType == typeof(Guid); Type repositoryImplementationType; if (Options.SpecifiedDefaultRepositoryTypes) { - repositoryImplementationType = isDefaultPrimaryKey - ? Options.DefaultRepositoryImplementationTypeWithDefaultPrimaryKey.MakeGenericType(entityType) - : Options.DefaultRepositoryImplementationType.MakeGenericType(entityType, primaryKeyType); + repositoryImplementationType = Options.DefaultRepositoryImplementationType.MakeGenericType(entityType, primaryKeyType); + //repositoryImplementationType = isDefaultPrimaryKey + // ? Options.DefaultRepositoryImplementationTypeWithDefaultPrimaryKey.MakeGenericType(entityType) + // : Options.DefaultRepositoryImplementationType.MakeGenericType(entityType, primaryKeyType); } else { - repositoryImplementationType = isDefaultPrimaryKey - ? GetRepositoryTypeForDefaultPk(Options.DefaultRepositoryDbContextType, entityType) - : GetRepositoryType(Options.DefaultRepositoryDbContextType, entityType, primaryKeyType); + repositoryImplementationType = GetRepositoryType(Options.DefaultRepositoryDbContextType, entityType, primaryKeyType); + //repositoryImplementationType = isDefaultPrimaryKey + // ? GetRepositoryTypeForDefaultPk(Options.DefaultRepositoryDbContextType, entityType) + // : GetRepositoryType(Options.DefaultRepositoryDbContextType, entityType, primaryKeyType); } services.AddDefaultRepository(entityType, repositoryImplementationType); @@ -87,7 +89,7 @@ namespace Volo.Abp.Domain.Repositories protected abstract IEnumerable GetEntityTypes(Type dbContextType); - protected abstract Type GetRepositoryTypeForDefaultPk(Type dbContextType, Type entityType); + //protected abstract Type GetRepositoryTypeForDefaultPk(Type dbContextType, Type entityType); protected abstract Type GetRepositoryType(Type dbContextType, Type entityType, Type primaryKeyType); } diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs index 869d090176..07047bd69b 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs @@ -11,15 +11,15 @@ using Volo.Abp.Threading; namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore { - public class EfCoreRepository : EfCoreRepository, IEfCoreRepository - where TDbContext : IEfCoreDbContext - where TEntity : class, IEntity - { - public EfCoreRepository(IDbContextProvider dbContextProvider) - : base(dbContextProvider) - { - } - } + //public class EfCoreRepository : EfCoreRepository, IEfCoreRepository + // where TDbContext : IEfCoreDbContext + // where TEntity : class, IEntity + //{ + // public EfCoreRepository(IDbContextProvider dbContextProvider) + // : base(dbContextProvider) + // { + // } + //} public class EfCoreRepository : QueryableRepositoryBase, IEfCoreRepository, diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs index e7e6ab171f..d32912d1d4 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs @@ -4,11 +4,11 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore { - public interface IEfCoreRepository : IEfCoreRepository, IQueryableRepository - where TEntity : class, IEntity - { + //public interface IEfCoreRepository : IEfCoreRepository, IQueryableRepository + // where TEntity : class, IEntity + //{ - } + //} public interface IEfCoreRepository : IQueryableRepository where TEntity : class, IEntity diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DependencyInjection/EfCoreRepositoryRegistrar.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DependencyInjection/EfCoreRepositoryRegistrar.cs index f481fadc69..db0dcdc13f 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DependencyInjection/EfCoreRepositoryRegistrar.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DependencyInjection/EfCoreRepositoryRegistrar.cs @@ -17,10 +17,10 @@ namespace Volo.Abp.EntityFrameworkCore.DependencyInjection return DbContextHelper.GetEntityTypes(dbContextType); } - protected override Type GetRepositoryTypeForDefaultPk(Type dbContextType, Type entityType) - { - return typeof(EfCoreRepository<,>).MakeGenericType(dbContextType, entityType); - } + //protected override Type GetRepositoryTypeForDefaultPk(Type dbContextType, Type entityType) + //{ + // return typeof(EfCoreRepository<,>).MakeGenericType(dbContextType, entityType); + //} protected override Type GetRepositoryType(Type dbContextType, Type entityType, Type primaryKeyType) { diff --git a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/IMemoryDbRepository.cs b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/IMemoryDbRepository.cs index 59f001195a..8eba8ede94 100644 --- a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/IMemoryDbRepository.cs +++ b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/IMemoryDbRepository.cs @@ -4,11 +4,11 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.Domain.Repositories.MemoryDb { - public interface IMemoryDbRepository : IMemoryDbRepository, IQueryableRepository - where TEntity : class, IEntity - { + //public interface IMemoryDbRepository : IMemoryDbRepository, IQueryableRepository + // where TEntity : class, IEntity + //{ - } + //} public interface IMemoryDbRepository : IQueryableRepository where TEntity : class, IEntity diff --git a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs index dcccdd6b07..bd2a03b4bb 100644 --- a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs +++ b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs @@ -6,15 +6,15 @@ using Volo.Abp.MemoryDb; namespace Volo.Abp.Domain.Repositories.MemoryDb { - public class MemoryDbRepository : MemoryDbRepository, IMemoryDbRepository - where TMemoryDbContext : MemoryDbContext - where TEntity : class, IEntity - { - public MemoryDbRepository(IMemoryDatabaseProvider databaseProvider) - : base(databaseProvider) - { - } - } + //public class MemoryDbRepository : MemoryDbRepository, IMemoryDbRepository + // where TMemoryDbContext : MemoryDbContext + // where TEntity : class, IEntity + //{ + // public MemoryDbRepository(IMemoryDatabaseProvider databaseProvider) + // : base(databaseProvider) + // { + // } + //} public class MemoryDbRepository : QueryableRepositoryBase, IMemoryDbRepository where TMemoryDbContext : MemoryDbContext diff --git a/src/Volo.Abp.MemoryDb/Volo/Abp/MemoryDb/DependencyInjection/MemoryDbRepositoryRegistrar.cs b/src/Volo.Abp.MemoryDb/Volo/Abp/MemoryDb/DependencyInjection/MemoryDbRepositoryRegistrar.cs index bf0d7dc011..08fa5d7a8f 100644 --- a/src/Volo.Abp.MemoryDb/Volo/Abp/MemoryDb/DependencyInjection/MemoryDbRepositoryRegistrar.cs +++ b/src/Volo.Abp.MemoryDb/Volo/Abp/MemoryDb/DependencyInjection/MemoryDbRepositoryRegistrar.cs @@ -18,11 +18,6 @@ namespace Volo.Abp.MemoryDb.DependencyInjection return memoryDbContext.GetEntityTypes(); } - protected override Type GetRepositoryTypeForDefaultPk(Type dbContextType, Type entityType) - { - return typeof(MemoryDbRepository<,>).MakeGenericType(dbContextType, entityType); - } - protected override Type GetRepositoryType(Type dbContextType, Type entityType, Type primaryKeyType) { return typeof(MemoryDbRepository<,,>).MakeGenericType(dbContextType, entityType, primaryKeyType); diff --git a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs index 82ffb23f6b..e33d7116c5 100644 --- a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs +++ b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs @@ -4,11 +4,11 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.Domain.Repositories.MongoDB { - public interface IMongoDbRepository : IMongoDbRepository, IQueryableRepository - where TEntity : class, IEntity - { + //public interface IMongoDbRepository : IMongoDbRepository, IQueryableRepository + // where TEntity : class, IEntity + //{ - } + //} public interface IMongoDbRepository : IQueryableRepository where TEntity : class, IEntity diff --git a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs index c18cb143b2..7ad3f6c29a 100644 --- a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs +++ b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs @@ -10,15 +10,15 @@ using Volo.Abp.MongoDB; namespace Volo.Abp.Domain.Repositories.MongoDB { - public class MongoDbRepository : MongoDbRepository, IMongoDbRepository - where TMongoDbContext : AbpMongoDbContext - where TEntity : class, IEntity - { - public MongoDbRepository(IMongoDatabaseProvider databaseProvider) - : base(databaseProvider) - { - } - } + //public class MongoDbRepository : MongoDbRepository, IMongoDbRepository + // where TMongoDbContext : AbpMongoDbContext + // where TEntity : class, IEntity + //{ + // public MongoDbRepository(IMongoDatabaseProvider databaseProvider) + // : base(databaseProvider) + // { + // } + //} public class MongoDbRepository : QueryableRepositoryBase, IMongoDbRepository where TMongoDbContext : AbpMongoDbContext diff --git a/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/MongoDbRepositoryRegistrar.cs b/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/MongoDbRepositoryRegistrar.cs index 0ab8861ff5..9b94969a59 100644 --- a/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/MongoDbRepositoryRegistrar.cs +++ b/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/MongoDbRepositoryRegistrar.cs @@ -19,11 +19,6 @@ namespace Volo.Abp.MongoDB.DependencyInjection return mongoDbContext.GetMappings().Select(m => m.EntityType); } - protected override Type GetRepositoryTypeForDefaultPk(Type dbContextType, Type entityType) - { - return typeof(MongoDbRepository<,>).MakeGenericType(dbContextType, entityType); - } - protected override Type GetRepositoryType(Type dbContextType, Type entityType, Type primaryKeyType) { return typeof(MongoDbRepository<,,>).MakeGenericType(dbContextType, entityType, primaryKeyType); diff --git a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs index 445e226de4..7c21ad6ee5 100644 --- a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs +++ b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs @@ -21,13 +21,13 @@ namespace Volo.Abp.AspNetCore.Mvc public class PersonAppService_Tests : AspNetCoreMvcTestBase { - private readonly IQueryableRepository _personRepository; + private readonly IQueryableRepository _personRepository; private readonly IJsonSerializer _jsonSerializer; private readonly IObjectMapper _objectMapper; public PersonAppService_Tests() { - _personRepository = ServiceProvider.GetRequiredService>(); + _personRepository = ServiceProvider.GetRequiredService>(); _jsonSerializer = ServiceProvider.GetRequiredService(); _objectMapper = ServiceProvider.GetRequiredService(); } diff --git a/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs b/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs index 8a0f7ae652..c9ba7b5b29 100644 --- a/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs +++ b/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs @@ -25,9 +25,9 @@ namespace Volo.Abp.Domain.Repositories //Assert - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); - services.ShouldNotContainService(typeof(IRepository)); + //services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); + services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); + services.ShouldNotContainService(typeof(IRepository)); } [Fact] @@ -46,9 +46,9 @@ namespace Volo.Abp.Domain.Repositories //Assert - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); + //services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); + services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); + services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); } [Fact] @@ -61,7 +61,7 @@ namespace Volo.Abp.Domain.Repositories var options = new TestDbContextRegistrationOptions(typeof(MyFakeDbContext)); options .AddDefaultRepositories(true) - .AddCustomRepository(); + .AddCustomRepository(); //Act @@ -69,9 +69,9 @@ namespace Volo.Abp.Domain.Repositories //Assert - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestAggregateRootWithDefaultPkCustomRepository)); - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestAggregateRootWithDefaultPkCustomRepository)); - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); + //services.ShouldContainTransient(typeof(IRepository), typeof(MyTestAggregateRootWithDefaultPkCustomRepository)); + services.ShouldContainTransient(typeof(IRepository), typeof(MyTestAggregateRootWithDefaultPkCustomRepository)); + services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); } [Fact] @@ -84,7 +84,7 @@ namespace Volo.Abp.Domain.Repositories var options = new TestDbContextRegistrationOptions(typeof(MyFakeDbContext)); options .AddDefaultRepositories(true) - .SetDefaultRepositoryClasses(typeof(MyTestCustomBaseRepository<,>), typeof(MyTestCustomBaseRepository<>)); + .SetDefaultRepositoryClasses(typeof(MyTestCustomBaseRepository<,>)); //Act @@ -92,9 +92,9 @@ namespace Volo.Abp.Domain.Repositories //Assert - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestCustomBaseRepository)); - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestCustomBaseRepository)); - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestCustomBaseRepository)); + //services.ShouldContainTransient(typeof(IRepository), typeof(MyTestCustomBaseRepository)); + services.ShouldContainTransient(typeof(IRepository), typeof(MyTestCustomBaseRepository)); + services.ShouldContainTransient(typeof(IRepository), typeof(MyTestCustomBaseRepository)); } public class MyTestRepositoryRegistrar : RepositoryRegistrarBase @@ -108,15 +108,15 @@ namespace Volo.Abp.Domain.Repositories { return new[] { - typeof(MyTestEntityWithCustomPk), - typeof(MyTestAggregateRootWithDefaultPk) + typeof(MyTestEntityWithInt32Pk), + typeof(MyTestAggregateRootWithGuidPk) }; } - protected override Type GetRepositoryTypeForDefaultPk(Type dbContextType, Type entityType) - { - return typeof(MyTestDefaultRepository<>).MakeGenericType(entityType); - } + //protected override Type GetRepositoryTypeForDefaultPk(Type dbContextType, Type entityType) + //{ + // return typeof(MyTestDefaultRepository<>).MakeGenericType(entityType); + //} protected override Type GetRepositoryType(Type dbContextType, Type entityType, Type primaryKeyType) { @@ -126,21 +126,21 @@ namespace Volo.Abp.Domain.Repositories public class MyFakeDbContext { } - public class MyTestAggregateRootWithDefaultPk : AggregateRoot + public class MyTestAggregateRootWithGuidPk : AggregateRoot { } - public class MyTestEntityWithCustomPk : Entity + public class MyTestEntityWithInt32Pk : Entity { } - public class MyTestDefaultRepository : MyTestDefaultRepository - where TEntity : class, IEntity - { + //public class MyTestDefaultRepository : MyTestDefaultRepository + // where TEntity : class, IEntity + //{ - } + //} public class MyTestDefaultRepository : RepositoryBase where TEntity : class, IEntity @@ -176,13 +176,7 @@ namespace Volo.Abp.Domain.Repositories } } - public class MyTestAggregateRootWithDefaultPkCustomRepository : MyTestDefaultRepository - { - - } - - public class MyTestCustomBaseRepository : MyTestCustomBaseRepository - where TEntity : class, IEntity + public class MyTestAggregateRootWithDefaultPkCustomRepository : MyTestDefaultRepository { } diff --git a/test/Volo.Abp.Identity.Tests/Volo/Abp/Identity/Initialize_Tests.cs b/test/Volo.Abp.Identity.Tests/Volo/Abp/Identity/Initialize_Tests.cs index 3eca23445e..b6a970e827 100644 --- a/test/Volo.Abp.Identity.Tests/Volo/Abp/Identity/Initialize_Tests.cs +++ b/test/Volo.Abp.Identity.Tests/Volo/Abp/Identity/Initialize_Tests.cs @@ -27,10 +27,10 @@ namespace Volo.Abp.Identity (ServiceProvider.GetRequiredService() is EfCoreIdentityUserRepository).ShouldBeTrue(); (ServiceProvider.GetRequiredService>() is EfCoreIdentityUserRepository).ShouldBeTrue(); - (ServiceProvider.GetRequiredService>() is EfCoreIdentityUserRepository).ShouldBeTrue(); + //(ServiceProvider.GetRequiredService>() is EfCoreIdentityUserRepository).ShouldBeTrue(); (ServiceProvider.GetRequiredService>() is EfCoreIdentityUserRepository).ShouldBeTrue(); - (ServiceProvider.GetRequiredService>() is EfCoreIdentityUserRepository).ShouldBeTrue(); + //(ServiceProvider.GetRequiredService>() is EfCoreIdentityUserRepository).ShouldBeTrue(); } } } diff --git a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MemoryDb_SoftDelete_DataFilter_Tests.cs b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MemoryDb_SoftDelete_DataFilter_Tests.cs index d627dfbabd..b3dc6cd4ed 100644 --- a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MemoryDb_SoftDelete_DataFilter_Tests.cs +++ b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MemoryDb_SoftDelete_DataFilter_Tests.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using Microsoft.Extensions.DependencyInjection; using Shouldly; using Volo.Abp.Data; @@ -10,12 +11,12 @@ namespace Volo.Abp.MemoryDb.DataFilters { public class MemoryDb_SoftDelete_DataFilter_Tests : MemoryDbTestBase { - private readonly IQueryableRepository _personRepository; + private readonly IQueryableRepository _personRepository; private readonly IDataFilter _dataFilter; public MemoryDb_SoftDelete_DataFilter_Tests() { - _personRepository = ServiceProvider.GetRequiredService>(); + _personRepository = ServiceProvider.GetRequiredService>(); _dataFilter = GetRequiredService(); } diff --git a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/MemoryDb_Basic_Repository_Tests.cs b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/MemoryDb_Basic_Repository_Tests.cs index 768460f0ba..9053d22363 100644 --- a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/MemoryDb_Basic_Repository_Tests.cs +++ b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/MemoryDb_Basic_Repository_Tests.cs @@ -10,11 +10,11 @@ namespace Volo.Abp.MemoryDb.Repositories { public class MemoryDb_Basic_Repository_Tests : MemoryDbTestBase { - private readonly IQueryableRepository _personRepository; + private readonly IQueryableRepository _personRepository; public MemoryDb_Basic_Repository_Tests() { - _personRepository = ServiceProvider.GetRequiredService>(); + _personRepository = ServiceProvider.GetRequiredService>(); } [Fact] diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPeopleAppService.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPeopleAppService.cs index 9a0188d96d..e356d452a2 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPeopleAppService.cs +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPeopleAppService.cs @@ -6,7 +6,7 @@ using Volo.Abp.TestApp.Application.Dto; namespace Volo.Abp.TestApp.Application { - public interface IPeopleAppService : IAsyncCrudAppService + public interface IPeopleAppService : IAsyncCrudAppService { Task> GetPhones(Guid id, GetPersonPhonesFilter filter); diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs index 0561f6fcef..7bc4ad087e 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs @@ -12,7 +12,7 @@ namespace Volo.Abp.TestApp.Application { public class PeopleAppService : AsyncCrudAppService, IPeopleAppService { - public PeopleAppService(IQueryableRepository repository) + public PeopleAppService(IQueryableRepository repository) : base(repository) { From d326b0b105d66baf642dae45b1b29daf71b8616f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 25 Jan 2018 10:16:13 +0300 Subject: [PATCH 04/14] Delete GetList and Count methods from the repository. --- .../Areas/Blog/Controllers/PostsController.cs | 6 +- .../IdentityServerTestController.cs | 2 +- src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll | Bin 15360 -> 13824 bytes .../Abp/Domain/Repositories/IRepository.cs | 32 +-------- .../Abp/Identity/IdentityRoleAppService.cs | 6 +- .../Abp/Identity/IIdentityRoleRepository.cs | 4 +- .../Abp/Identity/IIdentityUserRepository.cs | 14 ++-- ...ity.EntityFrameworkCore.csproj.DotSettings | 2 + .../Identity/EfCoreIdentityRoleRepository.cs | 11 ++- .../Identity/EfCoreIdentityUserRepository.cs | 4 +- ...p.IdentityServer.Domain.csproj.DotSettings | 2 + .../ApiResources/IApiResourceRepository.cs | 4 +- ...ver.EntityFrameworkCore.csproj.DotSettings | 2 + .../IdentityServer/ApiResourceRepository.cs | 8 +++ .../AspNetCore/Mvc/PersonAppService_Tests.cs | 15 ++-- .../DataFiltering/MultiTenant_Filter_Tests.cs | 66 ++++++++++-------- .../DataFiltering/SoftDelete_Filter_Tests.cs | 60 +++++++++------- .../Repositories/Basic_Repository_Tests.cs | 38 ++++++---- .../PersonAppServiceClientProxy_Tests.cs | 16 ++--- .../Identity/IdentityRoleAppService_Tests.cs | 1 - .../Identity/IdentityUserAppService_Tests.cs | 11 ++- .../MemoryDb_SoftDelete_DataFilter_Tests.cs | 10 +-- .../DataFilters/MultiTenant_Filter_Tests.cs | 19 +++-- .../MemoryDb_Basic_Repository_Tests.cs | 2 +- 24 files changed, 177 insertions(+), 158 deletions(-) create mode 100644 src/Volo.Abp.Identity.EntityFrameworkCore/Volo.Abp.Identity.EntityFrameworkCore.csproj.DotSettings create mode 100644 src/Volo.Abp.IdentityServer.Domain/Volo.Abp.IdentityServer.Domain.csproj.DotSettings create mode 100644 src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo.Abp.IdentityServer.EntityFrameworkCore.csproj.DotSettings diff --git a/src/AbpDesk/AbpDesk.MongoBlog/Areas/Blog/Controllers/PostsController.cs b/src/AbpDesk/AbpDesk.MongoBlog/Areas/Blog/Controllers/PostsController.cs index ec761ebfe4..c38b7a9c2c 100644 --- a/src/AbpDesk/AbpDesk.MongoBlog/Areas/Blog/Controllers/PostsController.cs +++ b/src/AbpDesk/AbpDesk.MongoBlog/Areas/Blog/Controllers/PostsController.cs @@ -1,5 +1,5 @@ using System; -using System.Threading.Tasks; +using System.Linq; using AbpDesk.Blogging; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc; @@ -17,9 +17,9 @@ namespace Areas.Blog.Controllers _blogPostRepository = blogPostRepository; } - public async Task Index() + public ActionResult Index() { - var posts = await _blogPostRepository.GetListAsync(HttpContext.RequestAborted); + var posts = _blogPostRepository.ToList(); //TODO: async..? return View(posts); } } diff --git a/src/AbpDesk/AbpDesk.Web.Mvc/Controllers/IdentityServerTestController.cs b/src/AbpDesk/AbpDesk.Web.Mvc/Controllers/IdentityServerTestController.cs index 365efc29ee..fdd402d4a4 100644 --- a/src/AbpDesk/AbpDesk.Web.Mvc/Controllers/IdentityServerTestController.cs +++ b/src/AbpDesk/AbpDesk.Web.Mvc/Controllers/IdentityServerTestController.cs @@ -38,7 +38,7 @@ namespace AbpDesk.Web.Mvc.Controllers [Route("create")] public async Task CreateClient(string clientId) { - var apiResource = (await _apiResourceRepository.GetListAsync()).FirstOrDefault(ar => ar.Name == "api1"); + var apiResource = await _apiResourceRepository.FindByNameAsync("api1"); if (apiResource == null) { diff --git a/src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll b/src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll index e18ffa8870111b6acf25bcd5eff6e366b5f589de..b1659c1e3458fd38570b90275dad352539769fea 100644 GIT binary patch delta 4463 zcmZWt4Rln+6}~fX_x0jSF~EO2LCG6#?t^QNRLqgqgI0zP7#V=TM>_l6psaKZNHh_VA2j}zjyC< z@7%dFbNB8Gi8YCq2R4OzV{6Y*YMh`@z|F=IML?)Y^3%G`?TbBj9nm~NG!m^*I)mwE zg2;sa*&L!uyR)LqUcyGZz9<6~z$aq=l$Elv_AWM>RoKT_sOSJ9h;b!8oSbA95|ssr zm>@AKXA!-qB2r0w1`nqbx!|YV1+$|B=Jc_gvhjrOBYvl#!+=s3SECtlc9)Wt^i!xo z#1lhVhZG%!V}=*4b3^!E4PskunQ$*m2uqkFLXomAZHQNz8WL_<(k;#Yj+g#u1mtio zz(qVN6(?r8wHQ)p4dbLr!y{oOH5w3}8i>p=7IT?`vYV8G+G)r=JW5!9aR19kNHR4C z36`ci44)&4gK@=RX^nXpwYK@-k{K-mStPCYL1lCtF-G{*wmdO?G)z<&^+1lzc~KN0;q6>eaJb_Juw+)I}cB^%hk$wwOliHtwOClET+m6-c~p~ zc9Wo@end!7S+RAJ!tD=G*|A3@mGc9Y6Wc8*T)yhEC_D)<$7r#BkfoVCIzV3r+HJ8b z!j+fS3{Qq=mXcl)X$xR>LR4Hyh=-?ur;-vH!N~y%I)JMfX zG>8h;5mjUFW#9`Iwa1!QE^iYj)iRvum;$b05nYM$^MWgw-B3Fd&ugK7=zu<>C3>T9 z#z0xKYx1@k26CWp*#yF-QK?jm4{DPTo>1e2FAiOf4?@Rj3)53aqw&~^N|v)lQ|VTT3nXrG2xgk&b6q7a@kz&joGQH! z9u@tCG%o_W=!jC!JhV`+Vivta)3HD&>r-9ywY#3F^ehE|QKe7Kq!ausdFULkVmb7x z!<&{vBNcC2KCRPgv>e)Kc53<5pwws~x|F??V!^sZUkul!6V!>5N+_ zD?nvZn$FNo=DByO5xUhuER)*JvpB_U^(=PwIF`3)Gp$BiuPD0^XcYFX((RJ}o#fZ> zN3qw1V8&CEUJqnuJ>pDr)o7Eb37A7}ph|nSJ~f}>hYg_|HT%$go^l;@hUh9?$< zG!OEV67*6Y3gcdK(?|-^cV-q}oS3SF_&C~Z6mmx0ECejz0u5dY+%K8RXh_5R0BuRReXLxWVFv022X|7>5aX*->&)7q{{*%ZNmpYp-^!fynbh7i4sb8R zoJ-kGnp;tr7gM&+O)sj27l;M-8~fZFxkfIjy=i>legIm!)b7TXQ2#mwq$+m!E3VV3 zq(%p^gqt==Z9kQ%TbW6FlbTVi2yLI#-ZaK5xD0wPWm^KzG&-EJEmOVt8h@O!J)=Fz zJ#;E%>(-u+L;WgcycRngMi)}Xo3Q*aV)*GI5}B&Faktb&qPt+Nlv*-1KOL1?^3?ov z>XN65`uIv}>rppva6kPkrH!Gtd0g}&M*l|7XH<*^!suBkCvh)26QjXsqs%yc#6@E| zFFl1k)Mv2&d`0-Ta<5mR6{^?kpqJ4K8Qp>&35>f9it7w77h;FmKo=DQy);hZWQo%y z)&etVfs~g>Tq?0y;wp)2CH4Yy$Y3JoIG~r70*k2wyh>|Xu~|d+vThSmazQoIBdpGh zqS}Sr#hy^^r{~xk&TVvr-qZd_udrpxpMbOYQR-!*(#}vHJFH%ylhS&U^{YBN%`TX^ zz+5xT82{8=!7kG8m1(SuLgv-1irQHdJ4gMBNV zA1h`ryZc!!-@p!|z3cQ3^wC;M=N851;t@fee+EoPKabD|@+uK3plo2N#0lu_5t=IH z8i{jg5|~BQ2>dZU3|vM}0dIq64Yko;Wf|Q`2b2z4Pu)P9b|~xVXSB!BC7CYC^wRn` z%)L@MDGev3{8uS6CMGi`CI_V)lybF{r>9U@8>O6(_=LpQB%Vm}T*P@o;%gF5NF<~* zzgr35(XCWVY?N3@-EGkj7FYe)wjx#q2uvAaf){u@4>-@k4+am&OS;S*nA%)2tm|9x=pE#lWbtJFRrK zMqvDGiX3czP|g_|=R3UI3|;Ru`#^F-WA}*{4~)U_l0R8Pxnw##p7fS@nmvW?@xP0V z7jHsxhz;C_@cqb4$elQVw`6xAx(8kw`bja>Q#oFVCeULvk+!4a{)YFYukqw;D*4zf z*k|K2m8P&8Xfsppr0sTZ`c(y2uWo5sdSgpd<2b6FwQ}`}rr3bCV0BY$tx)VK{v2m* zU3B?!JK?Xe5BTHuqKpRnlZ;cwr5W~t%tQ9O!|UzxtRlNHYqz~HdzSrfwr;J1?3XSZ_4u}$ zhesTF_nWP8btg zG{hHEgsYjSY1XO?Yc)h`ZH6_ATYg`ybr;X@B|4bX86Ych1aC6dDm-;e%ol|2LV{w7 z8uv2F%O}Ofat%@t{j?`9S1xl#CvL5^5@)zecqaq95dr&5Ttplpi$sO&B<}I#iiGZR z1jtuwWLOF9D?O(rCcYbUd^#NnosODjg`#M4-}OC;Ig>qt{^E>?pFx$=C< zCl6Bds5nmhq43CJu_X^Khhvp=tjauj9&xZ8d0cF@BWQRTcF_^E>x=8+T{&uW&q0?ROKg)1PgQ>KcqJ2Rvzw&Id=lgk7Yl!C{j z!{|#~j%*EKlviN}9L(eKBo*W=Y9RU8qJ+s~ghhA}PltpV_QsOFo_k6Q8QW*SP!@93 zHLqONbG%I9=JaLl&C!($o7z^lwA&XWV{9vuJ|dE=`*88pKzVunyqWW+1eUg~UAZh0 znPxYaPi558Renmztemmt9b$9mi)JPM;0n~?6R{tk5b|FC)}CQgZh3z8FQ2yi=e&M? vm)$?%25S%O1LKg81D(N4exR;rNyP%zteK)Rog{3;y(WH6s+LV-L_VDTj4<}uGmNER@rv9Rx9j#&P*WL z-3#;H?|Z-ReCIpoeCM2*qzBVm_kN?|J7Z;^Q}%hEDuQk{lV~moEkoYFdf&6_%-Jh6_>|7e( z;e}BP6~cE1a#6Lw4!3x17mC|r7KPwmr`;#?P%+$U5l5l5*)B=hX~9y}Fs*v0AHrn~ z`DlrT5_ndng(<|*zFOItJJqd9xRpt-T>C7qYbl2ussOl%$E4ywL$@AB|HC27WL*et zT%^S?YF9`Hksqpo=n<5?RH+QNV{9Re)HTWdy)(!(+Xf@6%T*1(8mog-9G2m@$!Iu% z%(eVjJ;-WlwO>$bQs|-BuO&)F^9GoxDrQ2CFX3o*8z9fpE(iXPS2m6wABM}MM4Yik z5k!xlo66HUx3gY%#;zCEv(U79U4v%dt~Rro_P5lE;4ERPeRSGxlohMWe+v`CLnsqh z{11qgm}CD^Z7oE-VYw&Pd1-cicxbMDy(5S+TII-R^Xz^{Q{jAg@)(>o9>cO~(}STK zL4|Izk2qGkQ6VDEvplrG&e7(lmdHNicPKQ>L!zmi;U}x6#rp&m%R_`LRS@4Psr+kH zVf?QpRdkIiioYT$)Tib`eKjLygC2hiWL-XwP0$NLqX1K(maBb+7D4pXk+Zgfhgu<1 zZ82)`1F^!WX}(>Qu1l-ub-Zp3@$I6vx1)U2j2LP|lh|Sbs1#QWBXfBy9>QF?8d`aN zl}pw>ckb|sHeN1@KBZdRQbGt-N9R&}yD)k9ed2XFfc}bkV4@vDEkmdsIifY+E?zrO zF)Gi?P%VVC<{QLf6TU(WO@cbH!dg<+v{feC(%%tF;e%LQMH#X#3YIz9If zRD}J*wA#i*B_<#(w%@ghsU;;pb}QOc*DfX{wgOUKUI=~HA&BkKuS*4yedSJ~Z{i(7 zvXx!Q_`pzqLWF-2>vdKEx3-J+q8HI;<+8P5Oc^}^{a;anm5T>sJ;E6eM zMXL^NuS=tY63?m&T{-kJDp#XM?M0_X4@ulC@tY38xE)*I|1(wKAx8?^j4n!pQ#wtD z?4qaDL(HU~8GCT_`Po0gwTxeZXSphHjYD)9b1VeLso(9QAA1imjrNk@$5nx^d4=b% z6v;^b4E4k3tW)ssplv?&C`~DJlTh}sB0A=9=M>SH;?60flg?evBHChpBtU?E0BN1pDFrV%-!p>SM^Ip^&=?2HmET1A~6Yyre30?jI9b0sq z{)|@lVum#OOyd3EQx=_vA)kKZ-sPN4UXSQ_9I{6B#udGcc1rn|<`unyR(LLJ6?D=N zsf-(kO^arF4x1YJ6~oXdN&-KTY2B$`(JfNs%sCX1Xfd#elKMx8f6y(MquLeSm7=>a z)i=<7^HX%GIsZeuiOw5`*iG~yrqrTNV+bR&%!_(0ZSY(a#XNO*qgE!JIx^F0rF`sgzR9zelOC#Bp+z35_q z{8T~Z^hfh0zAk-KImTyE!2M&+sF@!FJ}+@UKLxo<$^#P9{B1CmkTu$;o&kQ}cn`S2 zeF6M3`WX0UiCuIl#c#mf`W4R?BT(|`I&v$kf?|{p6=<%2!l*B!(Q9V8!s!Q6J4q2& zEi`Yr@H|Nk&RL2=1yb8bYuJ26rROVzO+?Y~CE+!xoup3pBE>=PT(zZy@vKz$6?k0B zVI-U*2x=@+PA~^KrS^sqR($aEXKiQA6DX|0tnGs7!-lKK+P>wzP0^_~Ya8?40d0=d z9+b&Asa0wswceECq7Zx}Da(?h?@+V;TH zOaGm<9ngK`r7Kxmz}Tdiq~q%d(HlmYk%Z=x+DYRAKfzKtRFE}Z;y%iua;ar9^--PF zM5a5@6h16meGmPI?M?s?TKqw_#0j z`ilE}3O%L!d@9u#qQMuk**x5KjOKZD+Dry6X@>nEim4Fjq8UIR4sL-rN^FxD1_r28 z%IhU|OB|56MdCJzW5A*mPBszrl*H2{rtdU~Y5S98{7iFI(-xqQ#(+&UD)|yhsOzYN z9A*UgkUof=gGHj3**x<>s+aO{wp#rjonpV%UZojqq48Tf%>wFw0^jCeVsWPDm@M@% zD{~gIS<=jSfpZ2k`0vdY;1%ymR?d%j?_^XBsXy(@8uSy!t?@O9l%CxzUP%j+|n-t zi|JipC7lP>Nt{E!fxJM6an_qAaD~rTWLGpqqfombXaYt1RYg- z={b5+9i?4hM(I_0QGI~MQ}n81Oj2W#IxgkoQa&%`^HTnIDKjP-GbS1M@D$OC&`wL5Zyr@6IslQ{b1-PsnD+*{|3o zoR17ApNfsTPC0;G^RX%LY478}pGxL&T`(2KA>e=U130u@@^W$mIeF|<&eE7pt@vJ~ z(_*Tj29&`{8lmsfAlu3QioJp&XyR&G?8V7X53WM&_p8rNep0HFxrceRNDYs;Dkq*j zcDXN?{j$!cUj*eNqU55>&k;$;Z(L}pQQ%ZPa0HZnNa z-7^@ydlrQ|N22j{-y9z5i*9Y{i$rE4heRY|>(;1uSv0v~Ad!@D z$v#*;%|2+g%#-cc4kfz(GP-i8J+^sxFq(|^QGYZU2`8rNtD{>+q6p9vizn?f)+hGQ zbKhx@;kuID$!JG+@5X_lD0M}XQ}o0&qkS;%c5i!ZC>a+cjW6y_*nh|iY0WLOB9VkW zE%2jyjCpe7wj_R0^o%5|wgZ?u0B==4tTw+!_4MaO;lUgqoC zmPkf7H^M90-G|>J_M-*)_Uvi*D3~w%scGB%?cGDYQLKrW_cgIi(ILCI;Prguy>x4D zbXc&oE;blzZ0i{&d$cB?+>%V%9~K-$qRB|4$G)$y)rr}ZQ#bx{;Q*W7+%h*3Np2iS z(EskdQ7qDUuy`Z0ch$I6L>jh-OWqT!u{xR<8BB`#vTrU8xiRi|lEOoYXxzTHv`p`a zeLZ?xbgR9;bc0hYhirPW^wIIHWoMPtcP_sE$lzZjZ+UG0E1O0(=J`ksGUil*#PD04 z`TasQ1#qET9TGQdkV~x&Jz%9zF@IR7{`60UdK#)r=T=F;-_5KITIPjcUP8zveI{ef zSB4+Q%qnpPDHX8RgLb0j51EyI!4c%Fq`>cE+)D4m{|R3B`zE}O_@>&+$N_Wuh~Yzq zvYBxAlDf&Oe`WtFS+>6%*;|VS9dtA4FUfagc?C&R*ALE5hQDL7SKQ1 zloNzuy)@bMj6%0cScL37P1L{T`3W(iql>IOFv9(>Rc?PR%Jm5#VEPZMh( z(#1$neIQW~nb)^9656+2!iu@<$7JF{WQNqmT)Sk9Oh!Qkg>0H~{X*t-Lvv zMo)}KY7}13Eza(s*!j(w(>=4*TkN434ej0H#12M!24nrJa96C3;>H+A#^T!=aVA_n zp+jQ3i=#5SHQ6}%tSYV%;v0&U;`=OH0|MB8e#5z`q%TfH@<+VZH$<=i@&F2pDnBHvBo0ayL$X+V<&s;`o3{<=I<3_RrYVn Ov&a2&KV|!7>i+|)Eib45 diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs index f2bc729011..31dfd82682 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Threading; +using System.Threading; using System.Threading.Tasks; using JetBrains.Annotations; using Volo.Abp.DependencyInjection; @@ -22,19 +20,6 @@ namespace Volo.Abp.Domain.Repositories public interface IRepository : IRepository where TEntity : class, IEntity { - /// - /// Get list of all entities without any filtering. - /// - /// List of entities - List GetList(); - - /// - /// Get list of all entities without any filtering. - /// - /// A to observe while waiting for the task to complete. - /// List of entities - Task> GetListAsync(CancellationToken cancellationToken = default); - /// /// Gets an entity with given primary key. /// Throws if can not find an entity with given id. @@ -60,7 +45,7 @@ namespace Volo.Abp.Domain.Repositories /// Primary key of the entity to get /// Entity or null [CanBeNull] - TEntity Find(TPrimaryKey id); + TEntity Find(TPrimaryKey id); //TODO: Rename to FirstOrDefault..? /// /// Gets an entity with given primary key or null if not found. @@ -133,18 +118,5 @@ namespace Volo.Abp.Domain.Repositories /// A to observe while waiting for the task to complete. /// Primary key of the entity Task DeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default); //TODO: Return true if deleted - - /// - /// Get list of all entities without any filtering. - /// - /// List of entities - long GetCount(); - - /// - /// Get list of all entities without any filtering. - /// - /// A to observe while waiting for the task to complete. - /// List of entities - Task GetCountAsync(CancellationToken cancellationToken = default); } } diff --git a/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs b/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs index 08b2ff4faa..f6bee59fa8 100644 --- a/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs +++ b/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs @@ -26,10 +26,10 @@ namespace Volo.Abp.Identity ); } - public async Task> GetListAsync(GetIdentityRolesInput input) + public async Task> GetListAsync(GetIdentityRolesInput input) //TODO: Remove input { - var count = (int)await _roleRepository.GetCountAsync(); - var list = await _roleRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter); + var count = (int) await _roleRepository.GetCountAsync(); + var list = await _roleRepository.GetListAsync(); return new PagedResultDto( count, diff --git a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs index 97fb33377b..87cce9658a 100644 --- a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs +++ b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs @@ -10,6 +10,8 @@ namespace Volo.Abp.Identity { Task FindByNormalizedNameAsync(string normalizedRoleName, CancellationToken cancellationToken); - Task> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter); + Task> GetListAsync(string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0); + + Task GetCountAsync(CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs index cc376acdc8..d764d69d48 100644 --- a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs +++ b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs @@ -10,23 +10,25 @@ namespace Volo.Abp.Identity { public interface IIdentityUserRepository : IRepository { - Task FindByNormalizedUserNameAsync([NotNull] string normalizedUserName, CancellationToken cancellationToken); + Task FindByNormalizedUserNameAsync([NotNull] string normalizedUserName, CancellationToken cancellationToken = default); Task> GetRoleNamesAsync(Guid userId); - Task FindByLoginAsync([NotNull] string loginProvider, [NotNull] string providerKey, CancellationToken cancellationToken); + Task FindByLoginAsync([NotNull] string loginProvider, [NotNull] string providerKey, CancellationToken cancellationToken = default); - Task FindByNormalizedEmailAsync([NotNull] string normalizedEmail, CancellationToken cancellationToken); + Task FindByNormalizedEmailAsync([NotNull] string normalizedEmail, CancellationToken cancellationToken = default); //TODO: Why not return List instead of IList - Task> GetListByClaimAsync(Claim claim, CancellationToken cancellationToken); + Task> GetListByClaimAsync(Claim claim, CancellationToken cancellationToken = default); //TODO: Why not return List instead of IList - Task> GetListByNormalizedRoleNameAsync(string normalizedRoleName, CancellationToken cancellationToken); + Task> GetListByNormalizedRoleNameAsync(string normalizedRoleName, CancellationToken cancellationToken = default); //TODO: DTO can be used instead of parameters - Task> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter); + Task> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter, CancellationToken cancellationToken = default); Task> GetRolesAsync(Guid userId); + + Task GetCountAsync(CancellationToken cancellationToken = default); } } diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo.Abp.Identity.EntityFrameworkCore.csproj.DotSettings b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo.Abp.Identity.EntityFrameworkCore.csproj.DotSettings new file mode 100644 index 0000000000..58ad6c8854 --- /dev/null +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo.Abp.Identity.EntityFrameworkCore.csproj.DotSettings @@ -0,0 +1,2 @@ + + CSharp71 \ No newline at end of file diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs index 2a6c6db2bb..8788cdf3dc 100644 --- a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs @@ -23,13 +23,12 @@ namespace Volo.Abp.Identity return DbSet.FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, cancellationToken); } - public async Task> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter) + public async Task> GetListAsync(string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0) { - return await this.WhereIf( - !filter.IsNullOrWhiteSpace(), - r => r.Name.Contains(filter) - ).OrderBy(sorting ?? nameof(IdentityRole.Name)) - .PageBy(skipCount, maxResultCount).ToListAsync(); + return await this + .OrderBy(sorting ?? nameof(IdentityRole.Name)) + .PageBy(skipCount, maxResultCount) + .ToListAsync(); } } } \ No newline at end of file diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs index 3b33b65390..834b663072 100644 --- a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs @@ -81,7 +81,7 @@ namespace Volo.Abp.Identity return await query.ToListAsync(cancellationToken); } - public async Task> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter) + public async Task> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter, CancellationToken cancellationToken = default) { return await this.WhereIf( !filter.IsNullOrWhiteSpace(), @@ -90,7 +90,7 @@ namespace Volo.Abp.Identity u.Email.Contains(filter) ) .OrderBy(sorting ?? nameof(IdentityUser.UserName)) - .PageBy(skipCount, maxResultCount).ToListAsync(); + .PageBy(skipCount, maxResultCount).ToListAsync(cancellationToken); } public async Task> GetListAsync(string sorting, int maxResultCount, int skipCount) diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo.Abp.IdentityServer.Domain.csproj.DotSettings b/src/Volo.Abp.IdentityServer.Domain/Volo.Abp.IdentityServer.Domain.csproj.DotSettings new file mode 100644 index 0000000000..58ad6c8854 --- /dev/null +++ b/src/Volo.Abp.IdentityServer.Domain/Volo.Abp.IdentityServer.Domain.csproj.DotSettings @@ -0,0 +1,2 @@ + + CSharp71 \ No newline at end of file diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs index 1ae0e26295..1bc5d4793c 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs @@ -1,10 +1,12 @@ using System; +using System.Threading; +using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; namespace Volo.Abp.IdentityServer.ApiResources { public interface IApiResourceRepository : IRepository { - + Task FindByNameAsync(string name, CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo.Abp.IdentityServer.EntityFrameworkCore.csproj.DotSettings b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo.Abp.IdentityServer.EntityFrameworkCore.csproj.DotSettings new file mode 100644 index 0000000000..58ad6c8854 --- /dev/null +++ b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo.Abp.IdentityServer.EntityFrameworkCore.csproj.DotSettings @@ -0,0 +1,2 @@ + + CSharp71 \ No newline at end of file diff --git a/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResourceRepository.cs b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResourceRepository.cs index 359930e2e4..49e0715fb2 100644 --- a/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResourceRepository.cs +++ b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResourceRepository.cs @@ -1,4 +1,7 @@ using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.IdentityServer.ApiResources; @@ -12,5 +15,10 @@ namespace Volo.Abp.IdentityServer { } + + public async Task FindByNameAsync(string name, CancellationToken cancellationToken = default) + { + return await this.FirstOrDefaultAsync(ar => ar.Name == name, cancellationToken); + } } } \ No newline at end of file diff --git a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs index 7c21ad6ee5..cdf3b09bfa 100644 --- a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs +++ b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs @@ -3,7 +3,6 @@ using Shouldly; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Application.Dtos; -using Volo.Abp.TestApp.Application; using Volo.Abp.TestApp.Domain; using Xunit; using Volo.Abp.Domain.Repositories; @@ -42,7 +41,7 @@ namespace Volo.Abp.AspNetCore.Mvc [Fact] public async Task Get_Test() { - var firstPerson = _personRepository.GetList().First(); + var firstPerson = _personRepository.First(); var result = await GetResponseAsObjectAsync($"/api/app/people/{firstPerson.Id}"); result.Name.ShouldBe(firstPerson.Name); @@ -51,7 +50,7 @@ namespace Volo.Abp.AspNetCore.Mvc [Fact] public async Task Delete_Test() { - var firstPerson = _personRepository.GetList().First(); + var firstPerson = _personRepository.First(); await Client.DeleteAsync($"/api/app/people/{firstPerson.Id}"); @@ -89,7 +88,7 @@ namespace Volo.Abp.AspNetCore.Mvc { //Arrange - var firstPerson = _personRepository.GetList().First(); + var firstPerson = _personRepository.First(); var firstPersonAge = firstPerson.Age; //Persist to a variable since we are using in-memory database which shares same entity. var updateDto = _objectMapper.Map(firstPerson); updateDto.Age = updateDto.Age + 1; @@ -123,7 +122,7 @@ namespace Volo.Abp.AspNetCore.Mvc { //Arrange - var personToAddNewPhone = _personRepository.GetList().First(); + var personToAddNewPhone = _personRepository.First(); var phoneNumberToAdd = RandomHelper.GetRandom(1000000, 9000000).ToString(); //Act @@ -152,7 +151,7 @@ namespace Volo.Abp.AspNetCore.Mvc [Fact] public async Task GetPhones_Test() { - var douglas = _personRepository.GetList().First(p => p.Name == "Douglas"); + var douglas = _personRepository.First(p => p.Name == "Douglas"); var result = await GetResponseAsObjectAsync>($"/api/app/people/{douglas.Id}/phones"); result.Items.Count.ShouldBe(douglas.Phones.Count); @@ -161,12 +160,12 @@ namespace Volo.Abp.AspNetCore.Mvc [Fact] public async Task DeletePhone_Test() { - var douglas = _personRepository.GetList().First(p => p.Name == "Douglas"); + var douglas = _personRepository.First(p => p.Name == "Douglas"); var firstPhone = douglas.Phones.First(); await Client.DeleteAsync($"/api/app/people/{douglas.Id}/phones/{firstPhone.Id}"); - douglas = _personRepository.GetList().First(p => p.Name == "Douglas"); + douglas = _personRepository.First(p => p.Name == "Douglas"); douglas.Phones.Any(p => p.Id == firstPhone.Id).ShouldBeFalse(); } } diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/MultiTenant_Filter_Tests.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/MultiTenant_Filter_Tests.cs index 6fe033ebce..e236362bae 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/MultiTenant_Filter_Tests.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/MultiTenant_Filter_Tests.cs @@ -14,15 +14,15 @@ using Xunit; namespace Volo.Abp.EntityFrameworkCore.DataFiltering { - public class MultiTenant_Filter_Tests : EntityFrameworkCoreTestBase + public class MultiTenant_Filter_Tests : EntityFrameworkCoreTestBase //TODO: This class is same of Volo.Abp.MemoryDb.DataFilters.MemoryDb_MultiTenant_Filter_Tests. Can we share source code? { private ICurrentTenant _fakeCurrentTenant; - private readonly IRepository _personRepository; + private readonly IQueryableRepository _personRepository; private readonly IDataFilter _multiTenantFilter; public MultiTenant_Filter_Tests() { - _personRepository = GetRequiredService>(); + _personRepository = GetRequiredService>(); _multiTenantFilter = GetRequiredService>(); } @@ -33,48 +33,54 @@ namespace Volo.Abp.EntityFrameworkCore.DataFiltering } [Fact] - public async Task Should_Get_Person_For_Current_Tenant() + public void Should_Get_Person_For_Current_Tenant() { - //TenantId = null + WithUnitOfWork(() => + { + //TenantId = null - _fakeCurrentTenant.Id.Returns((Guid?)null); + _fakeCurrentTenant.Id.Returns((Guid?)null); - var people = await _personRepository.GetListAsync(); - people.Count.ShouldBe(1); - people.Any(p => p.Name == "Douglas").ShouldBeTrue(); + var people = _personRepository.ToList(); + people.Count.ShouldBe(1); + people.Any(p => p.Name == "Douglas").ShouldBeTrue(); - //TenantId = TestDataBuilder.TenantId1 + //TenantId = TestDataBuilder.TenantId1 - _fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId1); + _fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId1); - people = await _personRepository.GetListAsync(); - people.Count.ShouldBe(2); - people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person1").ShouldBeTrue(); - people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person2").ShouldBeTrue(); + people = _personRepository.ToList(); + people.Count.ShouldBe(2); + people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person1").ShouldBeTrue(); + people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person2").ShouldBeTrue(); - //TenantId = TestDataBuilder.TenantId2 + //TenantId = TestDataBuilder.TenantId2 - _fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId2); + _fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId2); - people = await _personRepository.GetListAsync(); - people.Count.ShouldBe(0); + people = _personRepository.ToList(); + people.Count.ShouldBe(0); + }); } [Fact] - public async Task Should_Get_All_People_When_MultiTenant_Filter_Is_Disabled() + public void Should_Get_All_People_When_MultiTenant_Filter_Is_Disabled() { - List people; - - using (_multiTenantFilter.Disable()) + WithUnitOfWork(() => { - //Filter disabled manually - people = await _personRepository.GetListAsync(); - people.Count.ShouldBe(3); - } + List people; + + using (_multiTenantFilter.Disable()) + { + //Filter disabled manually + people = _personRepository.ToList(); + people.Count.ShouldBe(3); + } - //Filter re-enabled automatically - people = await _personRepository.GetListAsync(); - people.Count.ShouldBe(1); + //Filter re-enabled automatically + people = _personRepository.ToList(); + people.Count.ShouldBe(1); + }); } } } diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/SoftDelete_Filter_Tests.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/SoftDelete_Filter_Tests.cs index fd087a4268..f845b2ca5f 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/SoftDelete_Filter_Tests.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/SoftDelete_Filter_Tests.cs @@ -10,56 +10,62 @@ namespace Volo.Abp.EntityFrameworkCore.DataFiltering { public class SoftDelete_Filter_Tests : EntityFrameworkCoreTestBase { - private readonly IRepository _personRepository; + private readonly IQueryableRepository _personRepository; private readonly IDataFilter _dataFilter; public SoftDelete_Filter_Tests() { - _personRepository = GetRequiredService>(); + _personRepository = GetRequiredService>(); _dataFilter = GetRequiredService(); } [Fact] public void Should_Not_Get_Deleted_Entities_By_Default() { - var people = _personRepository.GetList(); - people.Count.ShouldBe(1); - people.Any(p => p.Name == "Douglas").ShouldBeTrue(); + WithUnitOfWork(() => + { + var people = _personRepository.ToList(); + people.Count.ShouldBe(1); + people.Any(p => p.Name == "Douglas").ShouldBeTrue(); + }); } [Fact] public void Should_Get_Deleted_Entities_When_Filter_Is_Disabled() { - //Soft delete is enabled by default - var people = _personRepository.GetList(); - people.Any(p => !p.IsDeleted).ShouldBeTrue(); - people.Any(p => p.IsDeleted).ShouldBeFalse(); - - using (_dataFilter.Disable()) + WithUnitOfWork(() => { - //Soft delete is disabled - people = _personRepository.GetList(); + //Soft delete is enabled by default + var people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); - people.Any(p => p.IsDeleted).ShouldBeTrue(); + people.Any(p => p.IsDeleted).ShouldBeFalse(); - using (_dataFilter.Enable()) + using (_dataFilter.Disable()) { - //Soft delete is enabled again - people = _personRepository.GetList(); + //Soft delete is disabled + people = _personRepository.ToList(); + people.Any(p => !p.IsDeleted).ShouldBeTrue(); + people.Any(p => p.IsDeleted).ShouldBeTrue(); + + using (_dataFilter.Enable()) + { + //Soft delete is enabled again + people = _personRepository.ToList(); + people.Any(p => !p.IsDeleted).ShouldBeTrue(); + people.Any(p => p.IsDeleted).ShouldBeFalse(); + } + + //Soft delete is disabled (restored previous state) + people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); - people.Any(p => p.IsDeleted).ShouldBeFalse(); + people.Any(p => p.IsDeleted).ShouldBeTrue(); } - //Soft delete is disabled (restored previous state) - people = _personRepository.GetList(); + //Soft delete is enabled (restored previous state) + people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); - people.Any(p => p.IsDeleted).ShouldBeTrue(); - } - - //Soft delete is enabled (restored previous state) - people = _personRepository.GetList(); - people.Any(p => !p.IsDeleted).ShouldBeTrue(); - people.Any(p => p.IsDeleted).ShouldBeFalse(); + people.Any(p => p.IsDeleted).ShouldBeFalse(); + }); } } } diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Basic_Repository_Tests.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Basic_Repository_Tests.cs index 55f35f94da..480a698cb2 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Basic_Repository_Tests.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Basic_Repository_Tests.cs @@ -12,44 +12,56 @@ namespace Volo.Abp.EntityFrameworkCore.Repositories { public class Basic_Repository_Tests : EntityFrameworkCoreTestBase { - private readonly IRepository _personRepository; - private readonly IRepository _bookRepository; - private readonly IRepository _phoneInSecondDbContextRepository; + private readonly IQueryableRepository _personRepository; + private readonly IQueryableRepository _bookRepository; + private readonly IQueryableRepository _phoneInSecondDbContextRepository; public Basic_Repository_Tests() { - _personRepository = ServiceProvider.GetRequiredService>(); - _bookRepository = ServiceProvider.GetRequiredService>(); - _phoneInSecondDbContextRepository = ServiceProvider.GetRequiredService>(); + _personRepository = ServiceProvider.GetRequiredService>(); + _bookRepository = ServiceProvider.GetRequiredService>(); + _phoneInSecondDbContextRepository = ServiceProvider.GetRequiredService>(); } [Fact] public void GetPersonList() { - _personRepository.GetList().Any().ShouldBeTrue(); + WithUnitOfWork(() => + { + _personRepository.Any().ShouldBeTrue(); + }); } [Fact] public void GetBookList() { - _bookRepository.GetList().Any().ShouldBeTrue(); + WithUnitOfWork(() => + { + _bookRepository.Any().ShouldBeTrue(); + }); } [Fact] public void GetPhoneInSecondDbContextList() { - _phoneInSecondDbContextRepository.GetList().Any().ShouldBeTrue(); + WithUnitOfWork(() => + { + _phoneInSecondDbContextRepository.Any().ShouldBeTrue(); + }); } [Fact] public async Task InsertAsync() { - var personId = Guid.NewGuid(); + await WithUnitOfWorkAsync(async () => + { + var personId = Guid.NewGuid(); - await _personRepository.InsertAsync(new Person(personId, "Adam", 42)); + await _personRepository.InsertAsync(new Person(personId, "Adam", 42)); - var person = await _personRepository.FindAsync(personId); - person.ShouldNotBeNull(); + var person = await _personRepository.FindAsync(personId); + person.ShouldNotBeNull(); + }); } } } diff --git a/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs b/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs index 71fa487415..858b2e007a 100644 --- a/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs +++ b/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs @@ -15,18 +15,18 @@ namespace Volo.Abp.Http.DynamicProxying public class PersonAppServiceClientProxy_Tests : AbpHttpTestBase { private readonly IPeopleAppService _peopleAppService; - private readonly IRepository _personRepository; + private readonly IQueryableRepository _personRepository; public PersonAppServiceClientProxy_Tests() { _peopleAppService = ServiceProvider.GetRequiredService(); - _personRepository = ServiceProvider.GetRequiredService>(); + _personRepository = ServiceProvider.GetRequiredService>(); } [Fact] public async Task Get() { - var firstPerson = _personRepository.GetList().First(); + var firstPerson = _personRepository.First(); var person = await _peopleAppService.GetAsync(firstPerson.Id); person.ShouldNotBeNull(); @@ -45,11 +45,11 @@ namespace Volo.Abp.Http.DynamicProxying [Fact] public async Task Delete() { - var firstPerson = _personRepository.GetList().First(); + var firstPerson = _personRepository.First(); await _peopleAppService.DeleteAsync(firstPerson.Id); - firstPerson = _personRepository.GetList().FirstOrDefault(p => p.Id == firstPerson.Id); + firstPerson = _personRepository.FirstOrDefault(p => p.Id == firstPerson.Id); firstPerson.ShouldBeNull(); } @@ -69,7 +69,7 @@ namespace Volo.Abp.Http.DynamicProxying person.Id.ShouldNotBe(Guid.Empty); person.Name.ShouldBe(uniquePersonName); - var personInDb = _personRepository.GetList().FirstOrDefault(p => p.Name == uniquePersonName); + var personInDb = _personRepository.FirstOrDefault(p => p.Name == uniquePersonName); personInDb.ShouldNotBeNull(); personInDb.Id.ShouldBe(person.Id); } @@ -77,7 +77,7 @@ namespace Volo.Abp.Http.DynamicProxying [Fact] public async Task Update() { - var firstPerson = _personRepository.GetList().First(); + var firstPerson = _personRepository.First(); var uniquePersonName = Guid.NewGuid().ToString(); var person = await _peopleAppService.UpdateAsync( @@ -95,7 +95,7 @@ namespace Volo.Abp.Http.DynamicProxying person.Name.ShouldBe(uniquePersonName); person.Age.ShouldBe(firstPerson.Age); - var personInDb = _personRepository.GetList().FirstOrDefault(p => p.Id == firstPerson.Id); + var personInDb = _personRepository.FirstOrDefault(p => p.Id == firstPerson.Id); personInDb.ShouldNotBeNull(); personInDb.Id.ShouldBe(person.Id); personInDb.Name.ShouldBe(person.Name); diff --git a/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityRoleAppService_Tests.cs b/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityRoleAppService_Tests.cs index 1eedd46355..b73bb755fa 100644 --- a/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityRoleAppService_Tests.cs +++ b/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityRoleAppService_Tests.cs @@ -4,7 +4,6 @@ using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Xunit; using Shouldly; -using Volo.Abp.Application.Dtos; namespace Volo.Abp.Identity { diff --git a/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs b/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs index 7cb07c46b0..5c4f2f4a75 100644 --- a/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs +++ b/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Shouldly; using Volo.Abp.Application.Dtos; +using Volo.Abp.Domain.Entities; using Xunit; namespace Volo.Abp.Identity @@ -184,12 +185,18 @@ namespace Volo.Abp.Identity private async Task GetUserAsync(string userName) { - return (await _userRepository.GetListAsync()).First(u => u.UserName == userName); + var user = await FindUserAsync(userName); + if (user == null) + { + throw new EntityNotFoundException(); + } + + return user; } private async Task FindUserAsync(string userName) { - return (await _userRepository.GetListAsync()).FirstOrDefault(u => u.UserName == userName); + return await _userRepository.FindByNormalizedUserNameAsync(userName.ToUpperInvariant()); } private static string CreateRandomEmail() diff --git a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MemoryDb_SoftDelete_DataFilter_Tests.cs b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MemoryDb_SoftDelete_DataFilter_Tests.cs index b3dc6cd4ed..2bf2b7f612 100644 --- a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MemoryDb_SoftDelete_DataFilter_Tests.cs +++ b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MemoryDb_SoftDelete_DataFilter_Tests.cs @@ -24,33 +24,33 @@ namespace Volo.Abp.MemoryDb.DataFilters public void Should_Get_Deleted_Entities_When_Filter_Is_Disabled() { //Soft delete is enabled by default - var people = _personRepository.GetList(); + var people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeFalse(); using (_dataFilter.Disable()) { //Soft delete is disabled - people = _personRepository.GetList(); + people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeTrue(); using (_dataFilter.Enable()) { //Soft delete is enabled again - people = _personRepository.GetList(); + people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeFalse(); } //Soft delete is disabled (restored previous state) - people = _personRepository.GetList(); + people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeTrue(); } //Soft delete is enabled (restored previous state) - people = _personRepository.GetList(); + people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeFalse(); } diff --git a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MultiTenant_Filter_Tests.cs b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MultiTenant_Filter_Tests.cs index e3c5c5fc24..9df33e4899 100644 --- a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MultiTenant_Filter_Tests.cs +++ b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MultiTenant_Filter_Tests.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using NSubstitute; using Shouldly; @@ -17,12 +16,12 @@ namespace Volo.Abp.MemoryDb.DataFilters public class MemoryDb_MultiTenant_Filter_Tests : MemoryDbTestBase { private ICurrentTenant _fakeCurrentTenant; - private readonly IRepository _personRepository; + private readonly IQueryableRepository _personRepository; private readonly IDataFilter _multiTenantFilter; public MemoryDb_MultiTenant_Filter_Tests() { - _personRepository = GetRequiredService>(); + _personRepository = GetRequiredService>(); _multiTenantFilter = GetRequiredService>(); } @@ -33,13 +32,13 @@ namespace Volo.Abp.MemoryDb.DataFilters } [Fact] - public async Task Should_Get_Person_For_Current_Tenant() + public void Should_Get_Person_For_Current_Tenant() { //TenantId = null _fakeCurrentTenant.Id.Returns((Guid?)null); - var people = await _personRepository.GetListAsync(); + var people = _personRepository.ToList(); people.Count.ShouldBe(1); people.Any(p => p.Name == "Douglas").ShouldBeTrue(); @@ -47,7 +46,7 @@ namespace Volo.Abp.MemoryDb.DataFilters _fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId1); - people = await _personRepository.GetListAsync(); + people = _personRepository.ToList(); people.Count.ShouldBe(2); people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person1").ShouldBeTrue(); people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person2").ShouldBeTrue(); @@ -56,24 +55,24 @@ namespace Volo.Abp.MemoryDb.DataFilters _fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId2); - people = await _personRepository.GetListAsync(); + people = _personRepository.ToList(); people.Count.ShouldBe(0); } [Fact] - public async Task Should_Get_All_People_When_MultiTenant_Filter_Is_Disabled() + public void Should_Get_All_People_When_MultiTenant_Filter_Is_Disabled() { List people; using (_multiTenantFilter.Disable()) { //Filter disabled manually - people = await _personRepository.GetListAsync(); + people = _personRepository.ToList(); people.Count.ShouldBe(3); } //Filter re-enabled automatically - people = await _personRepository.GetListAsync(); + people = _personRepository.ToList(); people.Count.ShouldBe(1); } } diff --git a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/MemoryDb_Basic_Repository_Tests.cs b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/MemoryDb_Basic_Repository_Tests.cs index 9053d22363..3efb7d775e 100644 --- a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/MemoryDb_Basic_Repository_Tests.cs +++ b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/MemoryDb_Basic_Repository_Tests.cs @@ -20,7 +20,7 @@ namespace Volo.Abp.MemoryDb.Repositories [Fact] public void GetList() { - var people = _personRepository.GetList(); + var people = _personRepository.ToList(); people.Count.ShouldBeGreaterThan(0); } From 5bd4c78bd81a85ce8f2a0abc1f29504ea8899bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 25 Jan 2018 11:00:03 +0300 Subject: [PATCH 05/14] Enabled entity, repo and aggr root without pk. --- src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll | Bin 13824 -> 13824 bytes .../Volo/Abp/Domain/Entities/AggregateRoot.cs | 13 +-- .../Volo/Abp/Domain/Entities/Entity.cs | 27 +++--- .../Abp/Domain/Entities/IAggregateRoot.cs | 20 ++-- .../Volo/Abp/Domain/Entities/IEntity.cs | 21 ++--- .../Repositories/IQueryableRepository.cs | 15 ++- .../Abp/Domain/Repositories/IRepository.cs | 87 +++++++++--------- .../Repositories/QueryableRepositoryBase.cs | 84 ++++++++++++----- .../Abp/Domain/Repositories/RepositoryBase.cs | 86 ++++++----------- .../EntityFrameworkCore/EfCoreRepository.cs | 22 ++--- .../Identity/EfCoreIdentityRoleRepository.cs | 5 + .../Identity/EfCoreIdentityUserRepository.cs | 5 + .../Repositories/MongoDB/MongoDbRepository.cs | 12 --- .../CancellationTokenProviderExtensions.cs | 2 +- .../RepositoryRegistration_Tests.cs | 10 -- 15 files changed, 201 insertions(+), 208 deletions(-) diff --git a/src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll b/src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll index b1659c1e3458fd38570b90275dad352539769fea..e75d37d1ba920d4860c758db227497eab4ed1c25 100644 GIT binary patch delta 1158 zcmZXSU2GI(6o%jPO=tFJw%hHpMUrWgEeole!iLJm6d?)$jI|iB5`RLhH4D*IpepNy zQM21DkP;i(yCS7!Q`3?|`>p%TFYR}=kWg%sqx1#t&X9Gv_3)SO=)ka*k;b0)42xAmy zCX~m3N-`%U`9b&x-NVV-tnbBD+@}`u-R@^D!9!{b-y7J!DDUs$p6&Avl~A`*7!Ws! z@BA5dzg69@RyM2*+!k9xn0obK(4klL$3dsHpiE3J2CvD$X;mf@H^fZ@rc?wb=Bl-s zP+89fow~ishhW0%p9p+oAJmTRv>s7@ye!#%T;g3e`o&FRnN_9`PS3kQ(kSa^ZHLPG zP1|W2QDMwhCyn`zvAb36ds3D42|L;J8P958B4?9HF?=tsv}m8dpzqjDT}8!kN3tT8 z<4bpGC_}zYv<5lK=)u~ie2&&p-v0(4BJa1*tPWU3ieVRJXoDm%8Jtv8q4$W?b^AlE zdYx%}YM!DrJ~GFtO?i(&>Swz`^*qhOD%BmBq9mQNzorhgkFHP{e%zucI#92oc!Zha z*Kj@0mj$@VbPzUDNZ>AJt8gWnSg#hnUf78=Cy$|8Ifc}l8Wex==_YB88N?zCh|5Dd7GO>H;Y~?dR>)XwMTS8I4nFP zoSx5>H)mLQMmQ}5A8FKx3)emk^l-|dv+j7Ri%KhM S-0+IO40UadTc5tk-uDlj&Is24 delta 1161 zcmZXSeP~-%7{;IX+}@kq+%!$obaY&cNz+kEyRdF$cC27WHzC$JnKB(R&FF%bZmZjZ zQbg0Pwrn`IWk(!CBC8IEC}wb-8;*>Xjf9GS*nKfkSgW{o;8zrMYzm(HHvS==KYsUl zp7%ZPJ@;c|`^fgg`>LjP50|qC9-v#<51%F}iCXmeKA=mMmwbmp$aL`;L2zhE! zj0u;fXj3e5@-6ds>Qu?wO0UFs=oX9A-Fg(8@u+x0-5Z!_$atSpJ=+!>ru<1EaDZJA zH@qq3eyX@1jKP4=aF=Zs0oo-G`D}Vce&n;;_6i-dO;D?77DSG8%(J^>mP8Ob%9Yxj zKPSsRyJkXo;ETEam(0u7VQE`-+dIOGU7Sr|M(wh&k6jV%MvnX_EI6}O%gL>lO*#3R zWjDSr0=Qk7l=pnB+^?0sXGBh(wptrMQ?t67`D{EXjBnUw8^*nR<$cSpxhTT8&)FE3 z;tOYqzn?shQ#aC-l834rGcVH`%6MN_hsbyhM8$q%oWj^aDO$@(mWNVRI3fmPx;bDCP|to0Qo#5i520KE8(LP(%ags@&Q zu3p1@MqTPqR9#ncY>t1FbR;uJlBo&{ z3(VPtT)1K6=`j_0Q0i(*C&)jY3nqAhepUa5)I&(bQD0}NNFbw^sk{`x!gm(O+ot&9aXsLBcR z|CQUpEp$+>t37S6+nF9n4<|d2*qL6j9EpvomxlHXq=$A7C!PAx!@=NNi_bjN{O)_b zNA0h_{G$+(&bFqt, IAggregateRoot - //{ - //} + /// + public abstract class AggregateRoot : IAggregateRoot + { + + } + /// public abstract class AggregateRoot : Entity, IAggregateRoot { diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs index 6cc3303565..2ad2664f7d 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs @@ -1,23 +1,15 @@ -using System; -using System.Reflection; +using System.Reflection; namespace Volo.Abp.Domain.Entities { - ///// - ///// A shortcut of for default primary key type (). - ///// - //public abstract class Entity : Entity, IEntity - //{ + /// + public abstract class Entity : IEntity + { - //} + } - /// - /// - /// Basic implementation of IEntity interface. - /// An entity can inherit this class of directly implement to IEntity interface. - /// - /// Type of the primary key of the entity - public abstract class Entity : IEntity + /// + public abstract class Entity : Entity, IEntity { /// public virtual TPrimaryKey Id { get; set; } @@ -57,6 +49,11 @@ namespace Volo.Abp.Domain.Entities /// public override int GetHashCode() { + if (Id == null) + { + return 0; + } + return Id.GetHashCode(); } diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IAggregateRoot.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IAggregateRoot.cs index adb3f11d60..51d51a9677 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IAggregateRoot.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IAggregateRoot.cs @@ -1,13 +1,19 @@ -using System; - -namespace Volo.Abp.Domain.Entities +namespace Volo.Abp.Domain.Entities { - //public interface IAggregateRoot : IAggregateRoot, IEntity - //{ + /// + /// Defines an aggregate root. It's primary key may not be "Id" or it may have a composite primary key. + /// Use where possible for better integration to repositories and other structures in the framework. + /// + public interface IAggregateRoot : IEntity + { - //} + } - public interface IAggregateRoot : IEntity + /// + /// Defines an aggregate root with a single primary key with "Id" property. + /// + /// Type of the primary key of the entity + public interface IAggregateRoot : IAggregateRoot, IEntity { } diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs index ff798a8253..a2f17e3f82 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs @@ -1,20 +1,19 @@ -using System; - -namespace Volo.Abp.Domain.Entities +namespace Volo.Abp.Domain.Entities { - ///// - ///// A shortcut of for default primary key type (). - ///// - //public interface IEntity : IEntity - //{ + /// + /// Defines an entity. It's primary key may not be "Id" or it mah have a composite primary key. + /// Use where possible for better integration to repositories and other structures in the framework. + /// + public interface IEntity + { - //} + } /// - /// Defines interface for base entity type. All entities in the system must implement this interface. + /// Defines an entity with a single primary key with "Id" property. /// /// Type of the primary key of the entity - public interface IEntity + public interface IEntity : IEntity { /// /// Unique identifier for this entity. diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IQueryableRepository.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IQueryableRepository.cs index 08bb61a442..6a0e35e4ed 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IQueryableRepository.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IQueryableRepository.cs @@ -8,14 +8,8 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.Domain.Repositories { - //public interface IQueryableRepository : IQueryableRepository, IRepository - // where TEntity : class, IEntity - //{ - - //} - - public interface IQueryableRepository : IRepository, IQueryable - where TEntity : class, IEntity + public interface IQueryableRepository : IRepository, IQueryable + where TEntity : class, IEntity { /// /// Deletes many entities by function. @@ -36,4 +30,9 @@ namespace Volo.Abp.Domain.Repositories /// A condition to filter entities Task DeleteAsync([NotNull] Expression> predicate, CancellationToken cancellationToken = default); } + + public interface IQueryableRepository : IQueryableRepository, IRepository + where TEntity : class, IEntity + { + } } \ No newline at end of file diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs index 31dfd82682..1b70ff510f 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs @@ -6,55 +6,17 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.Domain.Repositories { + /// + /// Just to mark a class as repository. + /// public interface IRepository : ITransientDependency { } - //public interface IRepository : IRepository - // where TEntity : class, IEntity - //{ - - //} - - public interface IRepository : IRepository - where TEntity : class, IEntity + public interface IRepository : IRepository + where TEntity : class, IEntity { - /// - /// Gets an entity with given primary key. - /// Throws if can not find an entity with given id. - /// - /// Primary key of the entity to get - /// Entity - [NotNull] - TEntity Get(TPrimaryKey id); - - /// - /// Gets an entity with given primary key. - /// Throws if can not find an entity with given id. - /// - /// Primary key of the entity to get - /// A to observe while waiting for the task to complete. - /// Entity - [NotNull] - Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default); - - /// - /// Gets an entity with given primary key or null if not found. - /// - /// Primary key of the entity to get - /// Entity or null - [CanBeNull] - TEntity Find(TPrimaryKey id); //TODO: Rename to FirstOrDefault..? - - /// - /// Gets an entity with given primary key or null if not found. - /// - /// Primary key of the entity to get - /// A to observe while waiting for the task to complete. - /// Entity or null - Task FindAsync(TPrimaryKey id, CancellationToken cancellationToken = default); - /// /// Inserts a new entity. /// @@ -105,6 +67,45 @@ namespace Volo.Abp.Domain.Repositories /// A to observe while waiting for the task to complete. /// Entity to be deleted Task DeleteAsync([NotNull] TEntity entity, CancellationToken cancellationToken = default); //TODO: Return true if deleted + } + + public interface IRepository : IRepository + where TEntity : class, IEntity + { + /// + /// Gets an entity with given primary key. + /// Throws if can not find an entity with given id. + /// + /// Primary key of the entity to get + /// Entity + [NotNull] + TEntity Get(TPrimaryKey id); + + /// + /// Gets an entity with given primary key. + /// Throws if can not find an entity with given id. + /// + /// Primary key of the entity to get + /// A to observe while waiting for the task to complete. + /// Entity + [NotNull] + Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default); + + /// + /// Gets an entity with given primary key or null if not found. + /// + /// Primary key of the entity to get + /// Entity or null + [CanBeNull] + TEntity Find(TPrimaryKey id); + + /// + /// Gets an entity with given primary key or null if not found. + /// + /// Primary key of the entity to get + /// A to observe while waiting for the task to complete. + /// Entity or null + Task FindAsync(TPrimaryKey id, CancellationToken cancellationToken = default); /// /// Deletes an entity by primary key. diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs index 8bdc50b4b3..c3f67b0b33 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs @@ -11,14 +11,8 @@ using Volo.Abp.MultiTenancy; namespace Volo.Abp.Domain.Repositories { - //public abstract class QueryableRepositoryBase : QueryableRepositoryBase, IQueryableRepository - // where TEntity : class, IEntity - //{ - - //} - - public abstract class QueryableRepositoryBase : RepositoryBase, IQueryableRepository - where TEntity : class, IEntity + public abstract class QueryableRepositoryBase : RepositoryBase, IQueryableRepository + where TEntity : class, IEntity { public virtual Type ElementType => GetQueryable().ElementType; @@ -26,10 +20,6 @@ namespace Volo.Abp.Domain.Repositories public virtual IQueryProvider Provider => GetQueryable().Provider; - public IDataFilter DataFilter { get; set; } - - public ICurrentTenant CurrentTenant { get; set; } - IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); @@ -42,33 +32,70 @@ namespace Volo.Abp.Domain.Repositories protected abstract IQueryable GetQueryable(); - public override List GetList() + public virtual void Delete(Expression> predicate) { - return GetQueryable().ToList(); + foreach (var entity in GetQueryable().Where(predicate).ToList()) + { + Delete(entity); + } } - public override TEntity Find(TPrimaryKey id) + public virtual Task DeleteAsync(Expression> predicate, CancellationToken cancellationToken = default) + { + Delete(predicate); + return Task.CompletedTask; + } + } + + public abstract class QueryableRepositoryBase : QueryableRepositoryBase, IQueryableRepository + where TEntity : class, IEntity + { + public IDataFilter DataFilter { get; set; } + + public ICurrentTenant CurrentTenant { get; set; } + + public virtual TEntity Find(TPrimaryKey id) { return GetQueryable().FirstOrDefault(CreateEqualityExpressionForId(id)); } - public virtual void Delete(Expression> predicate) + public virtual TEntity Get(TPrimaryKey id) { - foreach (var entity in GetQueryable().Where(predicate).ToList()) + var entity = Find(id); + + if (entity == null) { - Delete(entity); + throw new EntityNotFoundException(typeof(TEntity), id); } + + return entity; } - public virtual Task DeleteAsync(Expression> predicate, CancellationToken cancellationToken = default) + public virtual Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default) { - Delete(predicate); - return Task.CompletedTask; + return Task.FromResult(Get(id)); } - public override long GetCount() + public virtual Task FindAsync(TPrimaryKey id, CancellationToken cancellationToken = default) { - return GetQueryable().LongCount(); + return Task.FromResult(Find(id)); + } + + public virtual void Delete(TPrimaryKey id) + { + var entity = Find(id); + if (entity == null) + { + return; + } + + Delete(entity); + } + + public virtual Task DeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + { + Delete(id); + return Task.CompletedTask; } protected virtual IQueryable ApplyDataFilters(IQueryable query) @@ -86,5 +113,16 @@ namespace Volo.Abp.Domain.Repositories return query; } + + protected static Expression> CreateEqualityExpressionForId(TPrimaryKey id) + { + var lambdaParam = Expression.Parameter(typeof(TEntity)); + var lambdaBody = Expression.Equal( + Expression.PropertyOrField(lambdaParam, "Id"), + Expression.Constant(id, typeof(TPrimaryKey)) + ); + + return Expression.Lambda>(lambdaBody, lambdaParam); + } } } \ No newline at end of file diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs index a1c890c600..bc52a145a8 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs @@ -1,21 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq.Expressions; -using System.Threading; +using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Entities; using Volo.Abp.Threading; namespace Volo.Abp.Domain.Repositories { - //public abstract class RepositoryBase : RepositoryBase, IRepository - // where TEntity : class, IEntity - //{ - - //} - - public abstract class RepositoryBase : IRepository - where TEntity : class, IEntity + public abstract class RepositoryBase : IRepository + where TEntity : class, IEntity { public ICancellationTokenProvider CancellationTokenProvider { get; set; } @@ -24,13 +15,37 @@ namespace Volo.Abp.Domain.Repositories CancellationTokenProvider = NullCancellationTokenProvider.Instance; } - public abstract List GetList(); + public abstract TEntity Insert(TEntity entity, bool autoSave = false); - public virtual Task> GetListAsync(CancellationToken cancellationToken = default) + public virtual Task InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) { - return Task.FromResult(GetList()); + return Task.FromResult(Insert(entity, autoSave)); } + public abstract TEntity Update(TEntity entity); + + public virtual Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default) + { + return Task.FromResult(Update(entity)); + } + + public abstract void Delete(TEntity entity); + + public virtual Task DeleteAsync(TEntity entity, CancellationToken cancellationToken = default) + { + Delete(entity); + return Task.CompletedTask; + } + + protected virtual CancellationToken GetCancellationToken(CancellationToken prefferedValue = default) + { + return CancellationTokenProvider.FallbackToProvider(prefferedValue); + } + } + + public abstract class RepositoryBase : RepositoryBase, IRepository + where TEntity : class, IEntity + { public virtual TEntity Get(TPrimaryKey id) { var entity = Find(id); @@ -55,28 +70,6 @@ namespace Volo.Abp.Domain.Repositories return Task.FromResult(Find(id)); } - public abstract TEntity Insert(TEntity entity, bool autoSave = false); - - public virtual Task InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) - { - return Task.FromResult(Insert(entity, autoSave)); - } - - public abstract TEntity Update(TEntity entity); - - public virtual Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default) - { - return Task.FromResult(Update(entity)); - } - - public abstract void Delete(TEntity entity); - - public virtual Task DeleteAsync(TEntity entity, CancellationToken cancellationToken = default) - { - Delete(entity); - return Task.CompletedTask; - } - public virtual void Delete(TPrimaryKey id) { var entity = Find(id); @@ -93,24 +86,5 @@ namespace Volo.Abp.Domain.Repositories Delete(id); return Task.CompletedTask; } - - public abstract long GetCount(); - - public virtual Task GetCountAsync(CancellationToken cancellationToken = default) - { - return Task.FromResult(GetCount()); - } - - protected static Expression> CreateEqualityExpressionForId(TPrimaryKey id) - { - var lambdaParam = Expression.Parameter(typeof(TEntity)); - - var lambdaBody = Expression.Equal( - Expression.PropertyOrField(lambdaParam, "Id"), - Expression.Constant(id, typeof(TPrimaryKey)) - ); - - return Expression.Lambda>(lambdaBody, lambdaParam); - } } } diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs index 07047bd69b..698df13738 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs @@ -46,14 +46,9 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore return DbSet.AsQueryable(); } - public override Task> GetListAsync(CancellationToken cancellationToken = default) - { - return DbSet.ToListAsync(CancellationTokenProvider.FallbackToProvider(cancellationToken)); - } - public override async Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default) { - var entity = await FindAsync(id, CancellationTokenProvider.FallbackToProvider(cancellationToken)); + var entity = await FindAsync(id, GetCancellationToken(cancellationToken)); if (entity == null) { @@ -70,7 +65,7 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore public override Task FindAsync(TPrimaryKey id, CancellationToken cancellationToken = default) { - return DbSet.FindAsync(new object[] { id }, CancellationTokenProvider.FallbackToProvider(cancellationToken)); + return DbSet.FindAsync(new object[] { id }, GetCancellationToken(cancellationToken)); } public override TEntity Insert(TEntity entity, bool autoSave = false) @@ -91,7 +86,7 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore if (autoSave) { - await DbContext.SaveChangesAsync(CancellationTokenProvider.FallbackToProvider(cancellationToken)); + await DbContext.SaveChangesAsync(GetCancellationToken(cancellationToken)); } return savedEntity; @@ -110,25 +105,20 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore public override async Task DeleteAsync(Expression> predicate, CancellationToken cancellationToken = default) { - var entities = await GetQueryable().Where(predicate).ToListAsync(CancellationTokenProvider.FallbackToProvider(cancellationToken)); + var entities = await GetQueryable().Where(predicate).ToListAsync(GetCancellationToken(cancellationToken)); foreach (var entity in entities) { DbSet.Remove(entity); } } - public override Task GetCountAsync(CancellationToken cancellationToken = default) - { - return GetQueryable().LongCountAsync(CancellationTokenProvider.FallbackToProvider(cancellationToken)); - } - public virtual Task EnsureCollectionLoadedAsync( TEntity entity, Expression>> propertyExpression, CancellationToken cancellationToken = default) where TProperty : class { - return DbContext.Entry(entity).Collection(propertyExpression).LoadAsync(CancellationTokenProvider.FallbackToProvider(cancellationToken)); + return DbContext.Entry(entity).Collection(propertyExpression).LoadAsync(GetCancellationToken(cancellationToken)); } public virtual Task EnsurePropertyLoadedAsync( @@ -137,7 +127,7 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore CancellationToken cancellationToken = default) where TProperty : class { - return DbContext.Entry(entity).Reference(propertyExpression).LoadAsync(CancellationTokenProvider.FallbackToProvider(cancellationToken)); + return DbContext.Entry(entity).Reference(propertyExpression).LoadAsync(GetCancellationToken(cancellationToken)); } } } diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs index 8788cdf3dc..864db178e0 100644 --- a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs @@ -30,5 +30,10 @@ namespace Volo.Abp.Identity .PageBy(skipCount, maxResultCount) .ToListAsync(); } + + public async Task GetCountAsync(CancellationToken cancellationToken = default) + { + return await this.LongCountAsync(cancellationToken); + } } } \ No newline at end of file diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs index 834b663072..a9e4c553df 100644 --- a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs @@ -107,5 +107,10 @@ namespace Volo.Abp.Identity return await query.ToListAsync(); } + + public async Task GetCountAsync(CancellationToken cancellationToken = default) + { + return await this.LongCountAsync(cancellationToken); + } } } diff --git a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs index 7ad3f6c29a..2465246e61 100644 --- a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs +++ b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs @@ -37,13 +37,6 @@ namespace Volo.Abp.Domain.Repositories.MongoDB DatabaseProvider = databaseProvider; } - //TODO: Override other methods? - - public override async Task> GetListAsync(CancellationToken cancellationToken = new CancellationToken()) - { - return await (await Collection.FindAsync(Builders.Filter.Empty, cancellationToken: cancellationToken)).ToListAsync(cancellationToken); - } - public override async Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default) { var entity = await FindAsync(id, cancellationToken); @@ -120,10 +113,5 @@ namespace Volo.Abp.Domain.Repositories.MongoDB { return Collection.AsQueryable(); } - - public override Task GetCountAsync(CancellationToken cancellationToken = default) - { - return Collection.CountAsync(Builders.Filter.Empty, cancellationToken: cancellationToken); - } } } \ No newline at end of file diff --git a/src/Volo.Abp.Threading/Volo/Abp/Threading/CancellationTokenProviderExtensions.cs b/src/Volo.Abp.Threading/Volo/Abp/Threading/CancellationTokenProviderExtensions.cs index 0f84c725c5..b1ad755db2 100644 --- a/src/Volo.Abp.Threading/Volo/Abp/Threading/CancellationTokenProviderExtensions.cs +++ b/src/Volo.Abp.Threading/Volo/Abp/Threading/CancellationTokenProviderExtensions.cs @@ -4,7 +4,7 @@ namespace Volo.Abp.Threading { public static class CancellationTokenProviderExtensions { - public static CancellationToken FallbackToProvider(this ICancellationTokenProvider provider, CancellationToken prefferedValue) + public static CancellationToken FallbackToProvider(this ICancellationTokenProvider provider, CancellationToken prefferedValue = default) { return prefferedValue == default ? provider.Token : prefferedValue; } diff --git a/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs b/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs index c9ba7b5b29..f5554f00b0 100644 --- a/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs +++ b/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs @@ -164,16 +164,6 @@ namespace Volo.Abp.Domain.Repositories { throw new NotImplementedException(); } - - public override long GetCount() - { - throw new NotImplementedException(); - } - - public override List GetList() - { - throw new NotImplementedException(); - } } public class MyTestAggregateRootWithDefaultPkCustomRepository : MyTestDefaultRepository From d2da1f5a55ece987bd80831774f52a13d95211b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 25 Jan 2018 11:33:35 +0300 Subject: [PATCH 06/14] Implemented a test entity without Id property. --- .../Volo/Abp/Application/Dtos/EntityDto.cs | 29 ++++--------------- .../Volo/Abp/Application/Dtos/IEntityDto.cs | 18 ++---------- .../Services/AsyncCrudAppService.cs | 17 ++--------- .../Application/Services/CrudAppService.cs | 15 +--------- .../Volo/Abp/Domain/Entities/Entity.cs | 8 +++-- .../Volo/Abp/Identity/IdentityRoleDto.cs | 5 ++-- .../Volo/Abp/Identity/IdentityUserDto.cs | 2 +- .../AspNetCore/Mvc/PersonAppService_Tests.cs | 4 +-- .../AutoMapper/SampleClasses/MyEntityDto.cs | 5 ++-- .../AutoMapper/SampleClasses/MyEntityDto2.cs | 3 +- .../SampleClasses/MyNotMappedDto.cs | 5 ++-- .../EntityFrameworkCore/TestAppDbContext.cs | 10 +++++++ .../Abp/TestApp/Application/Dto/PersonDto.cs | 5 ++-- .../Abp/TestApp/Application/Dto/PhoneDto.cs | 5 ++-- .../TestApp/Application/IPeopleAppService.cs | 2 +- .../TestApp/Application/PeopleAppService.cs | 6 ++-- .../Volo/Abp/TestApp/Domain/Phone.cs | 2 +- 17 files changed, 51 insertions(+), 90 deletions(-) diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Application/Dtos/EntityDto.cs b/src/Volo.Abp.Ddd/Volo/Abp/Application/Dtos/EntityDto.cs index 87f1457e86..aaf4e1da9a 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Application/Dtos/EntityDto.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Application/Dtos/EntityDto.cs @@ -1,33 +1,14 @@ -using System; - namespace Volo.Abp.Application.Dtos { - public class EntityDto : EntityDto, IEntityDto + public class EntityDto : IEntityDto //TODO: Consider to delete this class { - /// - /// Creates a new object. - /// - public EntityDto() - { - - } - - /// - /// Creates a new object. - /// - /// Id of the entity - public EntityDto(Guid id) - : base(id) + public override string ToString() { - + return $"[DTO: {GetType().Name}]"; } } - /// - /// Implements common properties for entity based DTOs. - /// - /// Type of the primary key - public class EntityDto : IEntityDto + public class EntityDto : EntityDto, IEntityDto { /// /// Id of the entity. @@ -53,7 +34,7 @@ namespace Volo.Abp.Application.Dtos public override string ToString() { - return $"[{GetType().Name}] Id = {Id}"; + return $"[DTO: {GetType().Name}] Id = {Id}"; } } } \ No newline at end of file diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Application/Dtos/IEntityDto.cs b/src/Volo.Abp.Ddd/Volo/Abp/Application/Dtos/IEntityDto.cs index 390e2fb743..00e0f98cdb 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Application/Dtos/IEntityDto.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Application/Dtos/IEntityDto.cs @@ -1,24 +1,12 @@ -using System; - -namespace Volo.Abp.Application.Dtos +namespace Volo.Abp.Application.Dtos { - /// - /// A shortcut of for default primary key type (). - /// - public interface IEntityDto : IEntityDto + public interface IEntityDto { } - /// - /// Defines common properties for entity based DTOs. - /// - /// - public interface IEntityDto + public interface IEntityDto : IEntityDto { - /// - /// Id of the entity. - /// TPrimaryKey Id { get; set; } } } \ No newline at end of file diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/AsyncCrudAppService.cs b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/AsyncCrudAppService.cs index 0ed329c655..2e631d2f4c 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/AsyncCrudAppService.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/AsyncCrudAppService.cs @@ -1,5 +1,4 @@ -using System; -using System.Linq; +using System.Linq; using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.Domain.Entities; @@ -8,18 +7,6 @@ using Volo.Abp.Linq; namespace Volo.Abp.Application.Services { - public abstract class AsyncCrudAppService - : AsyncCrudAppService - where TEntity : class, IEntity - where TEntityDto : IEntityDto - { - protected AsyncCrudAppService(IQueryableRepository repository) - : base(repository) - { - - } - } - public abstract class AsyncCrudAppService : AsyncCrudAppService where TEntity : class, IEntity @@ -49,7 +36,7 @@ namespace Volo.Abp.Application.Services where TGetAllInput : IPagedAndSortedResultRequest where TEntity : class, IEntity where TEntityDto : IEntityDto - where TCreateInput : IEntityDto + where TCreateInput : IEntityDto { protected AsyncCrudAppService(IQueryableRepository repository) : base(repository) diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppService.cs b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppService.cs index 127d0acd62..cec074f909 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppService.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppService.cs @@ -1,23 +1,10 @@ -using System; -using System.Linq; +using System.Linq; using Volo.Abp.Application.Dtos; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories; namespace Volo.Abp.Application.Services { - public abstract class CrudAppService - : CrudAppService - where TEntity : class, IEntity - where TEntityDto : IEntityDto - { - protected CrudAppService(IQueryableRepository repository) - : base(repository) - { - - } - } - public abstract class CrudAppService : CrudAppService where TEntity : class, IEntity diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs index 2ad2664f7d..185aad9767 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs @@ -5,7 +5,11 @@ namespace Volo.Abp.Domain.Entities /// public abstract class Entity : IEntity { - + /// + public override string ToString() + { + return $"[ENTITY: {GetType().Name}]"; + } } /// @@ -75,7 +79,7 @@ namespace Volo.Abp.Domain.Entities /// public override string ToString() { - return $"[{GetType().Name} {Id}]"; + return $"[ENTITY: {GetType().Name}] Id = {Id}"; } } } diff --git a/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityRoleDto.cs b/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityRoleDto.cs index cb48f53146..13aa96f41b 100644 --- a/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityRoleDto.cs +++ b/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityRoleDto.cs @@ -1,8 +1,9 @@ -using Volo.Abp.Application.Dtos; +using System; +using Volo.Abp.Application.Dtos; namespace Volo.Abp.Identity { - public class IdentityRoleDto : EntityDto + public class IdentityRoleDto : EntityDto { public string Name { get; set; } } diff --git a/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserDto.cs b/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserDto.cs index d2721a1911..a5a549545b 100644 --- a/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserDto.cs +++ b/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserDto.cs @@ -3,7 +3,7 @@ using Volo.Abp.Application.Dtos; namespace Volo.Abp.Identity { - public class IdentityUserDto : EntityDto + public class IdentityUserDto : EntityDto { public string UserName { get; set; } diff --git a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs index cdf3b09bfa..7076cdd5e0 100644 --- a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs +++ b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs @@ -163,10 +163,10 @@ namespace Volo.Abp.AspNetCore.Mvc var douglas = _personRepository.First(p => p.Name == "Douglas"); var firstPhone = douglas.Phones.First(); - await Client.DeleteAsync($"/api/app/people/{douglas.Id}/phones/{firstPhone.Id}"); + await Client.DeleteAsync($"/api/app/people/{douglas.Id}/phones?number={firstPhone.Number}"); douglas = _personRepository.First(p => p.Name == "Douglas"); - douglas.Phones.Any(p => p.Id == firstPhone.Id).ShouldBeFalse(); + douglas.Phones.Any(p => p.Number == firstPhone.Number).ShouldBeFalse(); } } } \ No newline at end of file diff --git a/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntityDto.cs b/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntityDto.cs index 61e3e9b3bd..1d34d6858a 100644 --- a/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntityDto.cs +++ b/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntityDto.cs @@ -1,9 +1,10 @@ -using Volo.Abp.Application.Dtos; +using System; +using Volo.Abp.Application.Dtos; namespace Volo.Abp.AutoMapper.SampleClasses { [AutoMap(typeof(MyEntity))] - public class MyEntityDto : EntityDto + public class MyEntityDto : EntityDto { public int Number { get; set; } } diff --git a/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntityDto2.cs b/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntityDto2.cs index b01af5a7f9..ba67552ca0 100644 --- a/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntityDto2.cs +++ b/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntityDto2.cs @@ -1,8 +1,9 @@ +using System; using Volo.Abp.Application.Dtos; namespace Volo.Abp.AutoMapper.SampleClasses { - public class MyEntityDto2 : EntityDto + public class MyEntityDto2 : EntityDto { public int Number { get; set; } } diff --git a/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyNotMappedDto.cs b/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyNotMappedDto.cs index a69e50d819..096da7799c 100644 --- a/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyNotMappedDto.cs +++ b/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyNotMappedDto.cs @@ -1,8 +1,9 @@ -using Volo.Abp.Application.Dtos; +using System; +using Volo.Abp.Application.Dtos; namespace Volo.Abp.AutoMapper.SampleClasses { - public class MyNotMappedDto : EntityDto + public class MyNotMappedDto : EntityDto { public int Number { get; set; } } diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs index f6088eb8a7..49deda972e 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs @@ -16,5 +16,15 @@ namespace Volo.Abp.TestApp.EntityFrameworkCore { } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + modelBuilder.Entity(b => + { + b.HasKey(p => new {p.PersonId, p.Number}); + }); + } } } diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/Dto/PersonDto.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/Dto/PersonDto.cs index 7075c0c3c9..57204f260f 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/Dto/PersonDto.cs +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/Dto/PersonDto.cs @@ -1,8 +1,9 @@ -using Volo.Abp.Application.Dtos; +using System; +using Volo.Abp.Application.Dtos; namespace Volo.Abp.TestApp.Application.Dto { - public class PersonDto : EntityDto + public class PersonDto : EntityDto { public string Name { get; set; } diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/Dto/PhoneDto.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/Dto/PhoneDto.cs index 203d4f5054..a71da2940a 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/Dto/PhoneDto.cs +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/Dto/PhoneDto.cs @@ -1,9 +1,8 @@ -using Volo.Abp.Application.Dtos; -using Volo.Abp.TestApp.Domain; +using Volo.Abp.TestApp.Domain; namespace Volo.Abp.TestApp.Application.Dto { - public class PhoneDto : EntityDto + public class PhoneDto { public string Number { get; set; } diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPeopleAppService.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPeopleAppService.cs index e356d452a2..6317d7d8ce 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPeopleAppService.cs +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPeopleAppService.cs @@ -12,7 +12,7 @@ namespace Volo.Abp.TestApp.Application Task AddPhone(Guid id, PhoneDto phoneDto); - Task RemovePhone(Guid id, long phoneId); + Task RemovePhone(Guid id, string number); Task GetWithComplexType(GetWithComplexTypeInput input); } diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs index 7bc4ad087e..bd21d9cf3f 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs @@ -10,7 +10,7 @@ using Volo.Abp.TestApp.Application.Dto; namespace Volo.Abp.TestApp.Application { - public class PeopleAppService : AsyncCrudAppService, IPeopleAppService + public class PeopleAppService : AsyncCrudAppService, IPeopleAppService { public PeopleAppService(IQueryableRepository repository) : base(repository) @@ -39,10 +39,10 @@ namespace Volo.Abp.TestApp.Application return ObjectMapper.Map(phone); } - public async Task RemovePhone(Guid id, long phoneId) + public async Task RemovePhone(Guid id, string number) { var person = await GetEntityByIdAsync(id); - person.Phones.RemoveAll(p => p.Id == phoneId); + person.Phones.RemoveAll(p => p.Number == number); } public Task GetWithComplexType(GetWithComplexTypeInput input) diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Phone.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Phone.cs index 8519bea092..45f31c705b 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Phone.cs +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Phone.cs @@ -5,7 +5,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.TestApp.Domain { [Table("AppPhones")] - public class Phone : Entity + public class Phone : Entity { public virtual Guid PersonId { get; set; } From 924ba47fe5961b08abe42a6ed1995dd4d831d761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 26 Jan 2018 10:02:34 +0300 Subject: [PATCH 07/14] Register repositories without PK. --- .../ServiceCollectionRepositoryExtensions.cs | 75 +++++------ .../CommonDbContextRegistrationOptions.cs | 26 ++-- ...mmonDbContextRegistrationOptionsBuilder.cs | 6 +- .../Volo/Abp/Domain/Entities/EntityHelper.cs | 50 +++++--- .../Entities/EntityNotFoundException.cs | 9 ++ .../Abp/Domain/Entities/IAggregateRoot.cs | 2 +- .../Repositories/QueryableRepositoryBase.cs | 54 ++++---- .../Repositories/RepositoryRegistrarBase.cs | 37 +++--- .../EntityFrameworkCore/EfCoreRepository.cs | 119 +++++++++++------- .../EntityFrameworkCore/IEfCoreRepository.cs | 17 ++- .../EntityFrameworkCore/DbContextHelper.cs | 2 +- .../EfCoreRepositoryRegistrar.cs | 8 +- .../AbpIdentityEntityFrameworkCoreModule.cs | 4 +- .../AbpIdentityServerModule.cs | 2 +- .../MemoryDb/IMemoryDbRepository.cs | 19 ++- .../MemoryDb/MemoryDbRepository.cs | 89 ++++++++++--- .../MemoryDbRepositoryRegistrar.cs | 5 + .../MongoDbRepositoryRegistrar.cs | 5 + .../Volo.Abp.Ddd.Tests.csproj | 1 + .../Volo.Abp.Ddd.Tests.csproj.DotSettings | 2 + .../RepositoryRegistration_Tests.cs | 91 ++++++++++---- .../SecondContext/PhoneInSecondDbContext.cs | 7 +- .../TestApp/SecondContext/SecondDbContext.cs | 10 ++ .../AbpEntityFrameworkCoreTestModule.cs | 2 +- ...epository_Tests.cs => Repository_Tests.cs} | 8 +- 25 files changed, 400 insertions(+), 250 deletions(-) create mode 100644 test/Volo.Abp.Ddd.Tests/Volo.Abp.Ddd.Tests.csproj.DotSettings rename test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/{Basic_Repository_Tests.cs => Repository_Tests.cs} (89%) diff --git a/src/Volo.Abp.Ddd/Microsoft/Extensions/DependencyInjection/ServiceCollectionRepositoryExtensions.cs b/src/Volo.Abp.Ddd/Microsoft/Extensions/DependencyInjection/ServiceCollectionRepositoryExtensions.cs index 34f16efc34..1e75094169 100644 --- a/src/Volo.Abp.Ddd/Microsoft/Extensions/DependencyInjection/ServiceCollectionRepositoryExtensions.cs +++ b/src/Volo.Abp.Ddd/Microsoft/Extensions/DependencyInjection/ServiceCollectionRepositoryExtensions.cs @@ -4,66 +4,49 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using Volo.Abp; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories; -using Volo.Abp.Reflection; namespace Microsoft.Extensions.DependencyInjection { public static class ServiceCollectionRepositoryExtensions { - public static void AddDefaultRepository(this IServiceCollection services, Type entityType, Type repositoryImplementationType) + public static IServiceCollection AddDefaultRepository(this IServiceCollection services, Type entityType, Type repositoryImplementationType) { - AddDefaultRepositoryForGenericPrimaryKey(services, entityType, repositoryImplementationType); - - //if (BothSupportsDefaultPrimaryKey(entityType, repositoryImplementationType)) - //{ - // AddDefaultRepositoryForDefaultPrimaryKey(services, entityType, repositoryImplementationType); - //} - } - - private static void AddDefaultRepositoryForGenericPrimaryKey(IServiceCollection services, Type entityType, Type repositoryImplementationType) - { - var primaryKeyType = EntityHelper.GetPrimaryKeyType(entityType); - - //IRepository - var repositoryInterface = typeof(IRepository<,>).MakeGenericType(entityType, primaryKeyType); - if (!repositoryInterface.GetTypeInfo().IsAssignableFrom(repositoryImplementationType)) + //IRepository + var repositoryInterfaceWithoutPk = typeof(IRepository<>).MakeGenericType(entityType); + if (!repositoryInterfaceWithoutPk.IsAssignableFrom(repositoryImplementationType)) { - throw new AbpException($"Given repositoryImplementationType ({repositoryImplementationType}) must implement {repositoryInterface}"); + throw new AbpException($"Given repositoryImplementationType ({repositoryImplementationType}) must implement {repositoryInterfaceWithoutPk}"); } - services.TryAddTransient(repositoryInterface, repositoryImplementationType); + services.TryAddTransient(repositoryInterfaceWithoutPk, repositoryImplementationType); - //IQueryableRepository - var queryableRepositoryInterface = typeof(IQueryableRepository<,>).MakeGenericType(entityType, primaryKeyType); - if (queryableRepositoryInterface.GetTypeInfo().IsAssignableFrom(repositoryImplementationType)) + //IQueryableRepository + var queryableRepositoryInterfaceWithPk = typeof(IQueryableRepository<>).MakeGenericType(entityType); + if (repositoryInterfaceWithoutPk.IsAssignableFrom(repositoryImplementationType)) { - services.TryAddTransient(queryableRepositoryInterface, repositoryImplementationType); + services.TryAddTransient(queryableRepositoryInterfaceWithPk, repositoryImplementationType); } - } - - //private static void AddDefaultRepositoryForDefaultPrimaryKey(IServiceCollection services, Type entityType, Type repositoryImplementationType) - //{ - // //IRepository - // var repositoryInterfaceWithDefaultPrimaryKey = typeof(IRepository<>).MakeGenericType(entityType); - // if (!repositoryInterfaceWithDefaultPrimaryKey.GetTypeInfo().IsAssignableFrom(repositoryImplementationType)) - // { - // throw new AbpException($"Given repositoryImplementationType ({repositoryImplementationType}) must implement {repositoryInterfaceWithDefaultPrimaryKey}"); - // } - // services.TryAddTransient(repositoryInterfaceWithDefaultPrimaryKey, repositoryImplementationType); + var primaryKeyType = EntityHelper.FindPrimaryKeyType(entityType); - // //IQueryableRepository - // var queryableRepositoryInterfaceWithDefaultPrimaryKey = typeof(IQueryableRepository<>).MakeGenericType(entityType); - // if (queryableRepositoryInterfaceWithDefaultPrimaryKey.GetTypeInfo().IsAssignableFrom(repositoryImplementationType)) - // { - // services.TryAddTransient(queryableRepositoryInterfaceWithDefaultPrimaryKey, repositoryImplementationType); - // } - //} + if (primaryKeyType != null) + { + //IRepository + var repositoryInterface = typeof(IRepository<,>).MakeGenericType(entityType, primaryKeyType); + if (repositoryInterface.GetTypeInfo().IsAssignableFrom(repositoryImplementationType)) + { + services.TryAddTransient(repositoryInterface, repositoryImplementationType); + } + + //IQueryableRepository + var queryableRepositoryInterface = typeof(IQueryableRepository<,>).MakeGenericType(entityType, primaryKeyType); + if (queryableRepositoryInterface.GetTypeInfo().IsAssignableFrom(repositoryImplementationType)) + { + services.TryAddTransient(queryableRepositoryInterface, repositoryImplementationType); + } + } - //private static bool BothSupportsDefaultPrimaryKey(Type entityType, Type repositoryImplementationType) - //{ - // return typeof(IEntity).GetTypeInfo().IsAssignableFrom(entityType) && - // ReflectionHelper.IsAssignableToGenericType(repositoryImplementationType, typeof(IRepository<>)); - //} + return services; + } } } \ No newline at end of file diff --git a/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/CommonDbContextRegistrationOptions.cs b/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/CommonDbContextRegistrationOptions.cs index cced597bd4..e195a348bf 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/CommonDbContextRegistrationOptions.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/CommonDbContextRegistrationOptions.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using JetBrains.Annotations; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories; using Volo.Abp.Reflection; @@ -20,7 +19,7 @@ namespace Volo.Abp.DependencyInjection public Type DefaultRepositoryImplementationType { get; private set; } - //public Type DefaultRepositoryImplementationTypeWithDefaultPrimaryKey { get; private set; } + public Type DefaultRepositoryImplementationTypeWithoutPrimaryKey { get; private set; } public bool RegisterDefaultRepositories { get; private set; } @@ -28,7 +27,7 @@ namespace Volo.Abp.DependencyInjection public Dictionary CustomRepositories { get; } - public bool SpecifiedDefaultRepositoryTypes => DefaultRepositoryImplementationType != null; // && DefaultRepositoryImplementationTypeWithDefaultPrimaryKey != null; + public bool SpecifiedDefaultRepositoryTypes => DefaultRepositoryImplementationType != null && DefaultRepositoryImplementationTypeWithoutPrimaryKey != null; protected CommonDbContextRegistrationOptions(Type originalDbContextType) { @@ -80,32 +79,37 @@ namespace Volo.Abp.DependencyInjection return this; } - public ICommonDbContextRegistrationOptionsBuilder AddCustomRepository() + public ICommonDbContextRegistrationOptionsBuilder AddRepository() { - WithCustomRepository(typeof(TEntity), typeof(TRepository)); + AddCustomRepository(typeof(TEntity), typeof(TRepository)); return this; } - public ICommonDbContextRegistrationOptionsBuilder SetDefaultRepositoryClasses([NotNull] Type repositoryImplementationType) + public ICommonDbContextRegistrationOptionsBuilder SetDefaultRepositoryClasses( + Type repositoryImplementationType, + Type repositoryImplementationTypeWithoutPrimaryKey + ) { Check.NotNull(repositoryImplementationType, nameof(repositoryImplementationType)); + Check.NotNull(repositoryImplementationTypeWithoutPrimaryKey, nameof(repositoryImplementationTypeWithoutPrimaryKey)); DefaultRepositoryImplementationType = repositoryImplementationType; + DefaultRepositoryImplementationTypeWithoutPrimaryKey = repositoryImplementationTypeWithoutPrimaryKey; return this; } - private void WithCustomRepository(Type entityType, Type repositoryType) + private void AddCustomRepository(Type entityType, Type repositoryType) { - if (!ReflectionHelper.IsAssignableToGenericType(entityType, typeof(IEntity<>))) + if (!typeof(IEntity).IsAssignableFrom(entityType)) { throw new AbpException($"Given entityType is not an entity: {entityType.AssemblyQualifiedName}. It must implement {typeof(IEntity<>).AssemblyQualifiedName}."); } - if (!ReflectionHelper.IsAssignableToGenericType(repositoryType, typeof(IRepository<,>))) + if (!ReflectionHelper.IsAssignableToGenericType(repositoryType, typeof(IRepository<>))) { - throw new AbpException($"Given repositoryType is not a repository: {entityType.AssemblyQualifiedName}. It must implement {typeof(IRepository<,>).AssemblyQualifiedName}."); + throw new AbpException($"Given repositoryType is not a repository: {entityType.AssemblyQualifiedName}. It must implement {typeof(IRepository<>).AssemblyQualifiedName}."); } CustomRepositories[entityType] = repositoryType; @@ -123,7 +127,7 @@ namespace Volo.Abp.DependencyInjection return false; } - if (!IncludeAllEntitiesForDefaultRepositories && !ReflectionHelper.IsAssignableToGenericType(entityType, typeof(IAggregateRoot<>))) + if (!IncludeAllEntitiesForDefaultRepositories && !typeof(IAggregateRoot).IsAssignableFrom(entityType)) { return false; } diff --git a/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/ICommonDbContextRegistrationOptionsBuilder.cs b/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/ICommonDbContextRegistrationOptionsBuilder.cs index b78c2d7e67..c68b544ce2 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/ICommonDbContextRegistrationOptionsBuilder.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/ICommonDbContextRegistrationOptionsBuilder.cs @@ -1,4 +1,5 @@ using System; +using JetBrains.Annotations; namespace Volo.Abp.DependencyInjection { @@ -41,14 +42,15 @@ namespace Volo.Abp.DependencyInjection /// /// Entity type /// Repository type - ICommonDbContextRegistrationOptionsBuilder AddCustomRepository(); //TODO: Rename to AddRepository! + ICommonDbContextRegistrationOptionsBuilder AddRepository(); /// /// Uses given class(es) for default repositories. /// /// Repository implementation type + /// Repository implementation type (without primary key) /// - ICommonDbContextRegistrationOptionsBuilder SetDefaultRepositoryClasses(Type repositoryImplementationType); + ICommonDbContextRegistrationOptionsBuilder SetDefaultRepositoryClasses([NotNull] Type repositoryImplementationType, [NotNull] Type repositoryImplementationTypeWithoutPrimaryKey); /// /// Replaces given DbContext type with this DbContext type. diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/EntityHelper.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/EntityHelper.cs index 2dd23b4a08..3dee5b0ee5 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/EntityHelper.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/EntityHelper.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; +using System.Linq.Expressions; using System.Reflection; using JetBrains.Annotations; -using Volo.Abp.Reflection; namespace Volo.Abp.Domain.Entities { @@ -13,18 +13,9 @@ namespace Volo.Abp.Domain.Entities { public static bool IsEntity([NotNull] Type type) { - return ReflectionHelper.IsAssignableToGenericType(type, typeof (IEntity<>)); + return typeof(IEntity).IsAssignableFrom(type); } - /// - /// Default implementation of . - /// - /// This method is not used normally if given entity is derived from . - /// Just directly call . - /// - /// This method is exists to help developers who want to directly implement - /// but want to use default IsTransient implementation as a shortcut. - /// public static bool IsTransient(IEntity entity) // TODO: Completely remove IsTransient { if (EqualityComparer.Default.Equals(entity.Id, default)) @@ -46,25 +37,50 @@ namespace Volo.Abp.Domain.Entities return false; } - public static Type GetPrimaryKeyType() + /// + /// Tries to find the primary key type of the given entity type. + /// May return null if given type does not implement + /// + [CanBeNull] + public static Type FindPrimaryKeyType() + where TEntity : IEntity { - return GetPrimaryKeyType(typeof (TEntity)); + return FindPrimaryKeyType(typeof(TEntity)); } /// - /// Gets primary key type of given entity type + /// Tries to find the primary key type of the given entity type. + /// May return null if given type does not implement /// - public static Type GetPrimaryKeyType([NotNull] Type entityType) + [CanBeNull] + public static Type FindPrimaryKeyType([NotNull] Type entityType) { + if (!typeof(IEntity).IsAssignableFrom(entityType)) + { + throw new AbpException($"Given {nameof(entityType)} is not an entity. It should implement {typeof(IEntity).AssemblyQualifiedName}!"); + } + foreach (var interfaceType in entityType.GetTypeInfo().GetInterfaces()) { - if (interfaceType.GetTypeInfo().IsGenericType && interfaceType.GetGenericTypeDefinition() == typeof (IEntity<>)) + if (interfaceType.GetTypeInfo().IsGenericType && interfaceType.GetGenericTypeDefinition() == typeof(IEntity<>)) { return interfaceType.GenericTypeArguments[0]; } } - throw new AbpException("Can not find primary key type of given entity type: " + entityType + ". Be sure that this entity type implements " + typeof(IEntity<>).AssemblyQualifiedName); + return null; + } + + public static Expression> CreateEqualityExpressionForId(TPrimaryKey id) + where TEntity : IEntity + { + var lambdaParam = Expression.Parameter(typeof(TEntity)); + var lambdaBody = Expression.Equal( + Expression.PropertyOrField(lambdaParam, "Id"), + Expression.Constant(id, typeof(TPrimaryKey)) + ); + + return Expression.Lambda>(lambdaBody, lambdaParam); } } } \ No newline at end of file diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/EntityNotFoundException.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/EntityNotFoundException.cs index a33a9b8a41..510d0384c2 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/EntityNotFoundException.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/EntityNotFoundException.cs @@ -25,6 +25,15 @@ namespace Volo.Abp.Domain.Entities } + /// + /// Creates a new object. + /// + public EntityNotFoundException(Type entityType) + : this(entityType, null, null) + { + + } + /// /// Creates a new object. /// diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IAggregateRoot.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IAggregateRoot.cs index 51d51a9677..5050df0cca 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IAggregateRoot.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IAggregateRoot.cs @@ -13,7 +13,7 @@ /// Defines an aggregate root with a single primary key with "Id" property. /// /// Type of the primary key of the entity - public interface IAggregateRoot : IAggregateRoot, IEntity + public interface IAggregateRoot : IEntity, IAggregateRoot { } diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs index c3f67b0b33..00ef2c07be 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs @@ -14,6 +14,10 @@ namespace Volo.Abp.Domain.Repositories public abstract class QueryableRepositoryBase : RepositoryBase, IQueryableRepository where TEntity : class, IEntity { + public IDataFilter DataFilter { get; set; } + + public ICurrentTenant CurrentTenant { get; set; } + public virtual Type ElementType => GetQueryable().ElementType; public virtual Expression Expression => GetQueryable().Expression; @@ -45,18 +49,31 @@ namespace Volo.Abp.Domain.Repositories Delete(predicate); return Task.CompletedTask; } + + //TODO: Is that needed..? + protected virtual IQueryable ApplyDataFilters(IQueryable query) + { + if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity))) + { + query = query.WhereIf(DataFilter.IsEnabled(), e => ((ISoftDelete)e).IsDeleted == false); + } + + if (typeof(IMultiTenant).IsAssignableFrom(typeof(TEntity))) + { + var tenantId = CurrentTenant.Id; + query = query.WhereIf(DataFilter.IsEnabled(), e => ((IMultiTenant)e).TenantId == tenantId); + } + + return query; + } } public abstract class QueryableRepositoryBase : QueryableRepositoryBase, IQueryableRepository where TEntity : class, IEntity { - public IDataFilter DataFilter { get; set; } - - public ICurrentTenant CurrentTenant { get; set; } - public virtual TEntity Find(TPrimaryKey id) { - return GetQueryable().FirstOrDefault(CreateEqualityExpressionForId(id)); + return GetQueryable().FirstOrDefault(EntityHelper.CreateEqualityExpressionForId(id)); } public virtual TEntity Get(TPrimaryKey id) @@ -97,32 +114,5 @@ namespace Volo.Abp.Domain.Repositories Delete(id); return Task.CompletedTask; } - - protected virtual IQueryable ApplyDataFilters(IQueryable query) - { - if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity))) - { - query = query.WhereIf(DataFilter.IsEnabled(), e => ((ISoftDelete)e).IsDeleted == false); - } - - if (typeof(IMultiTenant).IsAssignableFrom(typeof(TEntity))) - { - var tenantId = CurrentTenant.Id; - query = query.WhereIf(DataFilter.IsEnabled(), e => ((IMultiTenant)e).TenantId == tenantId); - } - - return query; - } - - protected static Expression> CreateEqualityExpressionForId(TPrimaryKey id) - { - var lambdaParam = Expression.Parameter(typeof(TEntity)); - var lambdaBody = Expression.Equal( - Expression.PropertyOrField(lambdaParam, "Id"), - Expression.Constant(id, typeof(TPrimaryKey)) - ); - - return Expression.Lambda>(lambdaBody, lambdaParam); - } } } \ No newline at end of file diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryRegistrarBase.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryRegistrarBase.cs index 544da02f10..9b5510de89 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryRegistrarBase.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryRegistrarBase.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Entities; -using Volo.Abp.Reflection; namespace Volo.Abp.Domain.Repositories { @@ -45,26 +44,26 @@ namespace Volo.Abp.Domain.Repositories protected void RegisterDefaultRepository(IServiceCollection services, Type entityType) { - var primaryKeyType = EntityHelper.GetPrimaryKeyType(entityType); - //var isDefaultPrimaryKey = primaryKeyType == typeof(Guid); + services.AddDefaultRepository( + entityType, + GetDefaultRepositoryImplementationType(entityType) + ); + } - Type repositoryImplementationType; - if (Options.SpecifiedDefaultRepositoryTypes) - { - repositoryImplementationType = Options.DefaultRepositoryImplementationType.MakeGenericType(entityType, primaryKeyType); - //repositoryImplementationType = isDefaultPrimaryKey - // ? Options.DefaultRepositoryImplementationTypeWithDefaultPrimaryKey.MakeGenericType(entityType) - // : Options.DefaultRepositoryImplementationType.MakeGenericType(entityType, primaryKeyType); - } - else + private Type GetDefaultRepositoryImplementationType(Type entityType) + { + var primaryKeyType = EntityHelper.FindPrimaryKeyType(entityType); + + if (primaryKeyType == null) { - repositoryImplementationType = GetRepositoryType(Options.DefaultRepositoryDbContextType, entityType, primaryKeyType); - //repositoryImplementationType = isDefaultPrimaryKey - // ? GetRepositoryTypeForDefaultPk(Options.DefaultRepositoryDbContextType, entityType) - // : GetRepositoryType(Options.DefaultRepositoryDbContextType, entityType, primaryKeyType); + return Options.SpecifiedDefaultRepositoryTypes + ? Options.DefaultRepositoryImplementationTypeWithoutPrimaryKey.MakeGenericType(entityType) + : GetRepositoryType(Options.DefaultRepositoryDbContextType, entityType); } - services.AddDefaultRepository(entityType, repositoryImplementationType); + return Options.SpecifiedDefaultRepositoryTypes + ? Options.DefaultRepositoryImplementationType.MakeGenericType(entityType, primaryKeyType) + : GetRepositoryType(Options.DefaultRepositoryDbContextType, entityType, primaryKeyType); } public bool ShouldRegisterDefaultRepositoryFor(Type entityType) @@ -79,7 +78,7 @@ namespace Volo.Abp.Domain.Repositories return false; } - if (!Options.IncludeAllEntitiesForDefaultRepositories && !ReflectionHelper.IsAssignableToGenericType(entityType, typeof(IAggregateRoot<>))) + if (!Options.IncludeAllEntitiesForDefaultRepositories && !typeof(IAggregateRoot).IsAssignableFrom(entityType)) { return false; } @@ -89,7 +88,7 @@ namespace Volo.Abp.Domain.Repositories protected abstract IEnumerable GetEntityTypes(Type dbContextType); - //protected abstract Type GetRepositoryTypeForDefaultPk(Type dbContextType, Type entityType); + protected abstract Type GetRepositoryType(Type dbContextType, Type entityType); protected abstract Type GetRepositoryType(Type dbContextType, Type entityType, Type primaryKeyType); } diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs index 698df13738..9bd7245b7a 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs @@ -7,30 +7,16 @@ using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Entities; using Volo.Abp.EntityFrameworkCore; -using Volo.Abp.Threading; namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore { - //public class EfCoreRepository : EfCoreRepository, IEfCoreRepository - // where TDbContext : IEfCoreDbContext - // where TEntity : class, IEntity - //{ - // public EfCoreRepository(IDbContextProvider dbContextProvider) - // : base(dbContextProvider) - // { - // } - //} - - public class EfCoreRepository : QueryableRepositoryBase, - IEfCoreRepository, - ISupportsExplicitLoading - + public class EfCoreRepository : QueryableRepositoryBase, IEfCoreRepository where TDbContext : IEfCoreDbContext - where TEntity : class, IEntity + where TEntity : class, IEntity { public virtual DbSet DbSet => DbContext.Set(); - DbContext IEfCoreRepository.DbContext => DbContext.As(); + DbContext IEfCoreRepository.DbContext => DbContext.As(); protected virtual TDbContext DbContext => _dbContextProvider.GetDbContext(); @@ -40,34 +26,7 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore { _dbContextProvider = dbContextProvider; } - - protected override IQueryable GetQueryable() - { - return DbSet.AsQueryable(); - } - - public override async Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default) - { - var entity = await FindAsync(id, GetCancellationToken(cancellationToken)); - - if (entity == null) - { - throw new EntityNotFoundException(typeof(TEntity), id); - } - - return entity; - } - - public override TEntity Find(TPrimaryKey id) - { - return DbSet.Find(id); - } - - public override Task FindAsync(TPrimaryKey id, CancellationToken cancellationToken = default) - { - return DbSet.FindAsync(new object[] { id }, GetCancellationToken(cancellationToken)); - } - + public override TEntity Insert(TEntity entity, bool autoSave = false) { var savedEntity = DbSet.Add(entity).Entity; @@ -103,6 +62,11 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore DbSet.Remove(entity); } + protected override IQueryable GetQueryable() + { + return DbSet.AsQueryable(); + } + public override async Task DeleteAsync(Expression> predicate, CancellationToken cancellationToken = default) { var entities = await GetQueryable().Where(predicate).ToListAsync(GetCancellationToken(cancellationToken)); @@ -130,4 +94,69 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore return DbContext.Entry(entity).Reference(propertyExpression).LoadAsync(GetCancellationToken(cancellationToken)); } } + + public class EfCoreRepository : EfCoreRepository, + IEfCoreRepository, + ISupportsExplicitLoading + + where TDbContext : IEfCoreDbContext + where TEntity : class, IEntity + { + public EfCoreRepository(IDbContextProvider dbContextProvider) + : base(dbContextProvider) + { + + } + + public TEntity Get(TPrimaryKey id) + { + var entity = Find(id); + + if (entity == null) + { + throw new EntityNotFoundException(typeof(TEntity), id); + } + + return entity; + } + + public virtual async Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + { + var entity = await FindAsync(id, GetCancellationToken(cancellationToken)); + + if (entity == null) + { + throw new EntityNotFoundException(typeof(TEntity), id); + } + + return entity; + } + + public virtual TEntity Find(TPrimaryKey id) + { + return DbSet.Find(id); + } + + public virtual Task FindAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + { + return DbSet.FindAsync(new object[] { id }, GetCancellationToken(cancellationToken)); + } + + public virtual void Delete(TPrimaryKey id) + { + var entity = Find(id); + if (entity == null) + { + return; + } + + Delete(entity); + } + + public virtual Task DeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + { + Delete(id); + return Task.CompletedTask; + } + } } diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs index d32912d1d4..8232f02fcd 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs @@ -1,20 +1,19 @@ -using System; using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Entities; namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore { - //public interface IEfCoreRepository : IEfCoreRepository, IQueryableRepository - // where TEntity : class, IEntity - //{ - - //} - - public interface IEfCoreRepository : IQueryableRepository - where TEntity : class, IEntity + public interface IEfCoreRepository : IQueryableRepository + where TEntity : class, IEntity { DbContext DbContext { get; } DbSet DbSet { get; } } + + public interface IEfCoreRepository : IEfCoreRepository, IQueryableRepository + where TEntity : class, IEntity + { + + } } \ No newline at end of file diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DbContextHelper.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DbContextHelper.cs index 06887c83c8..7c3a8707d4 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DbContextHelper.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DbContextHelper.cs @@ -16,7 +16,7 @@ namespace Volo.Abp.EntityFrameworkCore from property in dbContextType.GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance) where ReflectionHelper.IsAssignableToGenericType(property.PropertyType, typeof(DbSet<>)) && - ReflectionHelper.IsAssignableToGenericType(property.PropertyType.GenericTypeArguments[0], typeof(IEntity<>)) + typeof(IEntity).IsAssignableFrom(property.PropertyType.GenericTypeArguments[0]) select property.PropertyType.GenericTypeArguments[0]; } } diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DependencyInjection/EfCoreRepositoryRegistrar.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DependencyInjection/EfCoreRepositoryRegistrar.cs index db0dcdc13f..f75c4a0132 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DependencyInjection/EfCoreRepositoryRegistrar.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DependencyInjection/EfCoreRepositoryRegistrar.cs @@ -17,10 +17,10 @@ namespace Volo.Abp.EntityFrameworkCore.DependencyInjection return DbContextHelper.GetEntityTypes(dbContextType); } - //protected override Type GetRepositoryTypeForDefaultPk(Type dbContextType, Type entityType) - //{ - // return typeof(EfCoreRepository<,>).MakeGenericType(dbContextType, entityType); - //} + protected override Type GetRepositoryType(Type dbContextType, Type entityType) + { + return typeof(EfCoreRepository<,>).MakeGenericType(dbContextType, entityType); + } protected override Type GetRepositoryType(Type dbContextType, Type entityType, Type primaryKeyType) { diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreModule.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreModule.cs index fb3d42cb30..9951d6564b 100644 --- a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreModule.cs +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreModule.cs @@ -12,8 +12,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore services.AddAbpDbContext(options => { options.AddDefaultRepositories(); - options.AddCustomRepository(); - options.AddCustomRepository(); + options.AddRepository(); + options.AddRepository(); }); services.AddAssemblyOf(); diff --git a/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/AbpIdentityServerModule.cs b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/AbpIdentityServerModule.cs index 1d53416680..d27afaf01d 100644 --- a/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/AbpIdentityServerModule.cs +++ b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/AbpIdentityServerModule.cs @@ -14,7 +14,7 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore services.AddAbpDbContext(options => { options.AddDefaultRepositories(); - options.AddCustomRepository(); + options.AddRepository(); }); services.AddAssemblyOf(); diff --git a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/IMemoryDbRepository.cs b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/IMemoryDbRepository.cs index 8eba8ede94..8d43180088 100644 --- a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/IMemoryDbRepository.cs +++ b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/IMemoryDbRepository.cs @@ -1,20 +1,19 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using Volo.Abp.Domain.Entities; namespace Volo.Abp.Domain.Repositories.MemoryDb { - //public interface IMemoryDbRepository : IMemoryDbRepository, IQueryableRepository - // where TEntity : class, IEntity - //{ - - //} - - public interface IMemoryDbRepository : IQueryableRepository - where TEntity : class, IEntity + public interface IMemoryDbRepository : IQueryableRepository + where TEntity : class, IEntity { IMemoryDatabase Database { get; } List Collection { get; } } + + public interface IMemoryDbRepository : IMemoryDbRepository, IQueryableRepository + where TEntity : class, IEntity + { + + } } diff --git a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs index bd2a03b4bb..acd37028a4 100644 --- a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs +++ b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs @@ -1,24 +1,16 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; +using System.Threading.Tasks; using Volo.Abp.Domain.Entities; using Volo.Abp.MemoryDb; namespace Volo.Abp.Domain.Repositories.MemoryDb { - //public class MemoryDbRepository : MemoryDbRepository, IMemoryDbRepository - // where TMemoryDbContext : MemoryDbContext - // where TEntity : class, IEntity - //{ - // public MemoryDbRepository(IMemoryDatabaseProvider databaseProvider) - // : base(databaseProvider) - // { - // } - //} - - public class MemoryDbRepository : QueryableRepositoryBase, IMemoryDbRepository + public class MemoryDbRepository : QueryableRepositoryBase, IMemoryDbRepository where TMemoryDbContext : MemoryDbContext - where TEntity : class, IEntity + where TEntity : class, IEntity { public virtual List Collection => Database.Collection(); @@ -33,11 +25,41 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb public override TEntity Insert(TEntity entity, bool autoSave = false) { - SetIdIfNeeded(entity); Collection.Add(entity); return entity; } + public override TEntity Update(TEntity entity) + { + return entity; + } + + public override void Delete(TEntity entity) + { + Collection.Remove(entity); + } + + protected override IQueryable GetQueryable() + { + return ApplyDataFilters(Collection.AsQueryable()); + } + } + + public class MemoryDbRepository : MemoryDbRepository, IMemoryDbRepository + where TMemoryDbContext : MemoryDbContext + where TEntity : class, IEntity + { + public MemoryDbRepository(IMemoryDatabaseProvider databaseProvider) + : base(databaseProvider) + { + } + + public override TEntity Insert(TEntity entity, bool autoSave = false) + { + SetIdIfNeeded(entity); + return base.Insert(entity, autoSave); + } + private void SetIdIfNeeded(TEntity entity) { if (typeof(TPrimaryKey) == typeof(int) || typeof(TPrimaryKey) == typeof(long) || typeof(TPrimaryKey) == typeof(Guid)) @@ -49,19 +71,48 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb } } - public override TEntity Update(TEntity entity) + public virtual TEntity Find(TPrimaryKey id) { + return GetQueryable().FirstOrDefault(EntityHelper.CreateEqualityExpressionForId(id)); + } + + public virtual TEntity Get(TPrimaryKey id) + { + var entity = Find(id); + + if (entity == null) + { + throw new EntityNotFoundException(typeof(TEntity), id); + } + return entity; } - - public override void Delete(TEntity entity) + + public virtual Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default) { - Collection.Remove(entity); + return Task.FromResult(Get(id)); } - protected override IQueryable GetQueryable() + public virtual Task FindAsync(TPrimaryKey id, CancellationToken cancellationToken = default) { - return ApplyDataFilters(Collection.AsQueryable()); + return Task.FromResult(Find(id)); + } + + public virtual void Delete(TPrimaryKey id) + { + var entity = Find(id); + if (entity == null) + { + return; + } + + Delete(entity); + } + + public virtual Task DeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + { + Delete(id); + return Task.CompletedTask; } } } \ No newline at end of file diff --git a/src/Volo.Abp.MemoryDb/Volo/Abp/MemoryDb/DependencyInjection/MemoryDbRepositoryRegistrar.cs b/src/Volo.Abp.MemoryDb/Volo/Abp/MemoryDb/DependencyInjection/MemoryDbRepositoryRegistrar.cs index 08fa5d7a8f..fa238a780d 100644 --- a/src/Volo.Abp.MemoryDb/Volo/Abp/MemoryDb/DependencyInjection/MemoryDbRepositoryRegistrar.cs +++ b/src/Volo.Abp.MemoryDb/Volo/Abp/MemoryDb/DependencyInjection/MemoryDbRepositoryRegistrar.cs @@ -18,6 +18,11 @@ namespace Volo.Abp.MemoryDb.DependencyInjection return memoryDbContext.GetEntityTypes(); } + protected override Type GetRepositoryType(Type dbContextType, Type entityType) + { + return typeof(MemoryDbRepository<,>).MakeGenericType(dbContextType, entityType); + } + protected override Type GetRepositoryType(Type dbContextType, Type entityType, Type primaryKeyType) { return typeof(MemoryDbRepository<,,>).MakeGenericType(dbContextType, entityType, primaryKeyType); diff --git a/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/MongoDbRepositoryRegistrar.cs b/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/MongoDbRepositoryRegistrar.cs index 9b94969a59..6d9d76be77 100644 --- a/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/MongoDbRepositoryRegistrar.cs +++ b/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/MongoDbRepositoryRegistrar.cs @@ -19,6 +19,11 @@ namespace Volo.Abp.MongoDB.DependencyInjection return mongoDbContext.GetMappings().Select(m => m.EntityType); } + protected override Type GetRepositoryType(Type dbContextType, Type entityType) + { + throw new NotImplementedException(); + } + protected override Type GetRepositoryType(Type dbContextType, Type entityType, Type primaryKeyType) { return typeof(MongoDbRepository<,,>).MakeGenericType(dbContextType, entityType, primaryKeyType); diff --git a/test/Volo.Abp.Ddd.Tests/Volo.Abp.Ddd.Tests.csproj b/test/Volo.Abp.Ddd.Tests/Volo.Abp.Ddd.Tests.csproj index e3fd3e19f6..faf42e147e 100644 --- a/test/Volo.Abp.Ddd.Tests/Volo.Abp.Ddd.Tests.csproj +++ b/test/Volo.Abp.Ddd.Tests/Volo.Abp.Ddd.Tests.csproj @@ -2,6 +2,7 @@ netcoreapp2.0 + latest Volo.Abp.Ddd.Tests Volo.Abp.Ddd.Tests true diff --git a/test/Volo.Abp.Ddd.Tests/Volo.Abp.Ddd.Tests.csproj.DotSettings b/test/Volo.Abp.Ddd.Tests/Volo.Abp.Ddd.Tests.csproj.DotSettings new file mode 100644 index 0000000000..58ad6c8854 --- /dev/null +++ b/test/Volo.Abp.Ddd.Tests/Volo.Abp.Ddd.Tests.csproj.DotSettings @@ -0,0 +1,2 @@ + + CSharp71 \ No newline at end of file diff --git a/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs b/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs index f5554f00b0..372f3fb6b9 100644 --- a/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs +++ b/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Entities; @@ -25,8 +27,10 @@ namespace Volo.Abp.Domain.Repositories //Assert - //services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); + services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); + services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); + services.ShouldNotContainService(typeof(IRepository)); } @@ -46,8 +50,10 @@ namespace Volo.Abp.Domain.Repositories //Assert - //services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); + services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); + services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); + services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); } @@ -61,7 +67,7 @@ namespace Volo.Abp.Domain.Repositories var options = new TestDbContextRegistrationOptions(typeof(MyFakeDbContext)); options .AddDefaultRepositories(true) - .AddCustomRepository(); + .AddRepository(); //Act @@ -69,7 +75,8 @@ namespace Volo.Abp.Domain.Repositories //Assert - //services.ShouldContainTransient(typeof(IRepository), typeof(MyTestAggregateRootWithDefaultPkCustomRepository)); + services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); + services.ShouldContainTransient(typeof(IRepository), typeof(MyTestAggregateRootWithDefaultPkCustomRepository)); services.ShouldContainTransient(typeof(IRepository), typeof(MyTestAggregateRootWithDefaultPkCustomRepository)); services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); } @@ -84,7 +91,7 @@ namespace Volo.Abp.Domain.Repositories var options = new TestDbContextRegistrationOptions(typeof(MyFakeDbContext)); options .AddDefaultRepositories(true) - .SetDefaultRepositoryClasses(typeof(MyTestCustomBaseRepository<,>)); + .SetDefaultRepositoryClasses(typeof(MyTestCustomBaseRepository<,>), typeof(MyTestCustomBaseRepository<>)); //Act @@ -92,14 +99,15 @@ namespace Volo.Abp.Domain.Repositories //Assert - //services.ShouldContainTransient(typeof(IRepository), typeof(MyTestCustomBaseRepository)); + services.ShouldContainTransient(typeof(IRepository), typeof(MyTestCustomBaseRepository)); + services.ShouldContainTransient(typeof(IRepository), typeof(MyTestCustomBaseRepository)); services.ShouldContainTransient(typeof(IRepository), typeof(MyTestCustomBaseRepository)); services.ShouldContainTransient(typeof(IRepository), typeof(MyTestCustomBaseRepository)); } public class MyTestRepositoryRegistrar : RepositoryRegistrarBase { - public MyTestRepositoryRegistrar(CommonDbContextRegistrationOptions options) + public MyTestRepositoryRegistrar(CommonDbContextRegistrationOptions options) : base(options) { } @@ -109,14 +117,15 @@ namespace Volo.Abp.Domain.Repositories return new[] { typeof(MyTestEntityWithInt32Pk), - typeof(MyTestAggregateRootWithGuidPk) + typeof(MyTestAggregateRootWithGuidPk), + typeof(MyTestAggregateRootWithoutPk) }; } - //protected override Type GetRepositoryTypeForDefaultPk(Type dbContextType, Type entityType) - //{ - // return typeof(MyTestDefaultRepository<>).MakeGenericType(entityType); - //} + protected override Type GetRepositoryType(Type dbContextType, Type entityType) + { + return typeof(MyTestDefaultRepository<>).MakeGenericType(entityType); + } protected override Type GetRepositoryType(Type dbContextType, Type entityType, Type primaryKeyType) { @@ -128,7 +137,7 @@ namespace Volo.Abp.Domain.Repositories public class MyTestAggregateRootWithGuidPk : AggregateRoot { - + } public class MyTestEntityWithInt32Pk : Entity @@ -136,31 +145,59 @@ namespace Volo.Abp.Domain.Repositories } - //public class MyTestDefaultRepository : MyTestDefaultRepository - // where TEntity : class, IEntity - //{ - - //} + public class MyTestAggregateRootWithoutPk : AggregateRoot + { + public string MyId { get; set; } + } + + public class MyTestDefaultRepository : RepositoryBase + where TEntity : class, IEntity + { + public override TEntity Insert(TEntity entity, bool autoSave = false) + { + throw new NotImplementedException(); + } + + public override TEntity Update(TEntity entity) + { + throw new NotImplementedException(); + } + + public override void Delete(TEntity entity) + { + throw new NotImplementedException(); + } + } - public class MyTestDefaultRepository : RepositoryBase + public class MyTestDefaultRepository : MyTestDefaultRepository, IRepository where TEntity : class, IEntity { - public override TEntity Find(TPrimaryKey id) + public TEntity Get(TPrimaryKey id) { throw new NotImplementedException(); } - public override TEntity Insert(TEntity entity, bool autoSave = false) + public Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default) { throw new NotImplementedException(); } - public override TEntity Update(TEntity entity) + public TEntity Find(TPrimaryKey id) { throw new NotImplementedException(); } - public override void Delete(TEntity entity) + public Task FindAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + { + throw new NotImplementedException(); + } + + public void Delete(TPrimaryKey id) + { + throw new NotImplementedException(); + } + + public Task DeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) { throw new NotImplementedException(); } @@ -171,6 +208,12 @@ namespace Volo.Abp.Domain.Repositories } + public class MyTestCustomBaseRepository : MyTestDefaultRepository + where TEntity : class, IEntity + { + + } + public class MyTestCustomBaseRepository : MyTestDefaultRepository where TEntity : class, IEntity { @@ -179,7 +222,7 @@ namespace Volo.Abp.Domain.Repositories public class TestDbContextRegistrationOptions : CommonDbContextRegistrationOptions { - public TestDbContextRegistrationOptions(Type originalDbContextType) + public TestDbContextRegistrationOptions(Type originalDbContextType) : base(originalDbContextType) { } diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/PhoneInSecondDbContext.cs b/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/PhoneInSecondDbContext.cs index 7c4c317c00..568c8b6ba2 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/PhoneInSecondDbContext.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/PhoneInSecondDbContext.cs @@ -1,11 +1,14 @@ -using System.ComponentModel.DataAnnotations.Schema; +using System; +using System.ComponentModel.DataAnnotations.Schema; using Volo.Abp.Domain.Entities; namespace Volo.Abp.EntityFrameworkCore.TestApp.SecondContext { [Table("AppPhones")] - public class PhoneInSecondDbContext : AggregateRoot + public class PhoneInSecondDbContext : AggregateRoot { + public virtual Guid PersonId { get; set; } + public virtual string Number { get; set; } } } \ No newline at end of file diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/SecondDbContext.cs b/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/SecondDbContext.cs index d2b54bc699..f07ffbc5a3 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/SecondDbContext.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/SecondDbContext.cs @@ -12,5 +12,15 @@ namespace Volo.Abp.EntityFrameworkCore.TestApp.SecondContext : base(options) { } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + modelBuilder.Entity(b => + { + b.HasKey(p => new { p.PersonId, p.Number }); + }); + } } } \ No newline at end of file diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreTestModule.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreTestModule.cs index b6b77d26f8..9496844b0b 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreTestModule.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreTestModule.cs @@ -22,7 +22,7 @@ namespace Volo.Abp.EntityFrameworkCore services.AddAbpDbContext(options => { - options.AddDefaultRepositories(); + options.AddDefaultRepositories(true); options.ReplaceDbContext(); }); diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Basic_Repository_Tests.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Tests.cs similarity index 89% rename from test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Basic_Repository_Tests.cs rename to test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Tests.cs index 480a698cb2..7a98204652 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Basic_Repository_Tests.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Tests.cs @@ -10,17 +10,17 @@ using Xunit; namespace Volo.Abp.EntityFrameworkCore.Repositories { - public class Basic_Repository_Tests : EntityFrameworkCoreTestBase + public class Repository_Tests : EntityFrameworkCoreTestBase { private readonly IQueryableRepository _personRepository; private readonly IQueryableRepository _bookRepository; - private readonly IQueryableRepository _phoneInSecondDbContextRepository; + private readonly IQueryableRepository _phoneInSecondDbContextRepository; - public Basic_Repository_Tests() + public Repository_Tests() { _personRepository = ServiceProvider.GetRequiredService>(); _bookRepository = ServiceProvider.GetRequiredService>(); - _phoneInSecondDbContextRepository = ServiceProvider.GetRequiredService>(); + _phoneInSecondDbContextRepository = ServiceProvider.GetRequiredService>(); } [Fact] From 0e42600639618ca07af423b7a91468e1e58b6a1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 26 Jan 2018 11:08:02 +0300 Subject: [PATCH 08/14] Introduced repository without PR for mongodb. --- .../MongoDB/IMongoDbRepository.cs | 19 ++- .../Repositories/MongoDB/MongoDbRepository.cs | 121 +++++++++++------- ...ongoDbContextRegistrationOptionsBuilder.cs | 1 - .../MongoDbRepositoryRegistrar.cs | 2 +- 4 files changed, 86 insertions(+), 57 deletions(-) diff --git a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs index e33d7116c5..c20c5dca1e 100644 --- a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs +++ b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs @@ -1,17 +1,10 @@ -using System; -using MongoDB.Driver; +using MongoDB.Driver; using Volo.Abp.Domain.Entities; namespace Volo.Abp.Domain.Repositories.MongoDB { - //public interface IMongoDbRepository : IMongoDbRepository, IQueryableRepository - // where TEntity : class, IEntity - //{ - - //} - - public interface IMongoDbRepository : IQueryableRepository - where TEntity : class, IEntity + public interface IMongoDbRepository : IQueryableRepository + where TEntity : class, IEntity { IMongoDatabase Database { get; } @@ -19,4 +12,10 @@ namespace Volo.Abp.Domain.Repositories.MongoDB string CollectionName { get; } } + + public interface IMongoDbRepository : IMongoDbRepository, IQueryableRepository + where TEntity : class, IEntity + { + + } } diff --git a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs index 2465246e61..3141da949e 100644 --- a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs +++ b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading; @@ -10,19 +9,9 @@ using Volo.Abp.MongoDB; namespace Volo.Abp.Domain.Repositories.MongoDB { - //public class MongoDbRepository : MongoDbRepository, IMongoDbRepository - // where TMongoDbContext : AbpMongoDbContext - // where TEntity : class, IEntity - //{ - // public MongoDbRepository(IMongoDatabaseProvider databaseProvider) - // : base(databaseProvider) - // { - // } - //} - - public class MongoDbRepository : QueryableRepositoryBase, IMongoDbRepository + public class MongoDbRepository : QueryableRepositoryBase, IMongoDbRepository where TMongoDbContext : AbpMongoDbContext - where TEntity : class, IEntity + where TEntity : class, IEntity { public virtual string CollectionName => DatabaseProvider.DbContext.GetCollectionName(); @@ -37,18 +26,6 @@ namespace Volo.Abp.Domain.Repositories.MongoDB DatabaseProvider = databaseProvider; } - public override async Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default) - { - var entity = await FindAsync(id, cancellationToken); - - if (entity == null) - { - throw new EntityNotFoundException(typeof(TEntity), id); - } - - return entity; - } - public override TEntity Insert(TEntity entity, bool autoSave = false) { Collection.InsertOne(entity); @@ -63,55 +40,109 @@ namespace Volo.Abp.Domain.Repositories.MongoDB public override TEntity Update(TEntity entity) { - var filter = Builders.Filter.Eq(e => e.Id, entity.Id); - Collection.ReplaceOne(filter, entity); + Collection.ReplaceOne(CreateEntityFilter(entity), entity); return entity; } public override async Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default) { - var filter = Builders.Filter.Eq(e => e.Id, entity.Id); - await Collection.ReplaceOneAsync(filter, entity, cancellationToken: cancellationToken); + await Collection.ReplaceOneAsync(CreateEntityFilter(entity), entity, cancellationToken: cancellationToken); return entity; } public override void Delete(TEntity entity) { - Delete(entity.Id); + Collection.DeleteOne(CreateEntityFilter(entity)); } - public override void Delete(TPrimaryKey id) + public override async Task DeleteAsync(TEntity entity, CancellationToken cancellationToken = default) { - var filter = Builders.Filter.Eq(e => e.Id, id); - Collection.DeleteOne(filter); + await Collection.DeleteOneAsync(CreateEntityFilter(entity), cancellationToken); } public override void Delete(Expression> predicate) { - var filter = Builders.Filter.Where(predicate); - Collection.DeleteOne(filter); + Collection.DeleteMany(Builders.Filter.Where(predicate)); } - public override Task DeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + public override async Task DeleteAsync(Expression> predicate, CancellationToken cancellationToken = default) { - var filter = Builders.Filter.Eq(e => e.Id, id); - return Collection.DeleteOneAsync(filter, cancellationToken: cancellationToken); + await Collection.DeleteManyAsync(Builders.Filter.Where(predicate), cancellationToken); } - public override Task DeleteAsync(TEntity entity, CancellationToken cancellationToken = default) + protected override IQueryable GetQueryable() { - return DeleteAsync(entity.Id, cancellationToken); + return Collection.AsQueryable(); } - public override Task DeleteAsync(Expression> predicate, CancellationToken cancellationToken = default) + protected virtual FilterDefinition CreateEntityFilter(TEntity entity) { - var filter = Builders.Filter.Where(predicate); - return Collection.DeleteOneAsync(filter, cancellationToken: cancellationToken); + throw new NotImplementedException("CreateEntityFilter is not implemented for MongoDb by default. It should be overrided and implemented by deriving classes!"); } + } - protected override IQueryable GetQueryable() + public class MongoDbRepository : MongoDbRepository, IMongoDbRepository + where TMongoDbContext : AbpMongoDbContext + where TEntity : class, IEntity + { + public MongoDbRepository(IMongoDatabaseProvider databaseProvider) + : base(databaseProvider) { - return Collection.AsQueryable(); + + } + + public virtual TEntity Get(TPrimaryKey id) + { + var entity = Find(id); + + if (entity == null) + { + throw new EntityNotFoundException(typeof(TEntity), id); + } + + return entity; + } + + public virtual async Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + { + var entity = await FindAsync(id, cancellationToken); + + if (entity == null) + { + throw new EntityNotFoundException(typeof(TEntity), id); + } + + return entity; + } + + public virtual void Delete(TPrimaryKey id) + { + Collection.DeleteOne(CreateEntityFilter(id)); + } + + public virtual Task DeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + { + return Collection.DeleteOneAsync(CreateEntityFilter(id), cancellationToken); + } + + public virtual async Task FindAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + { + return await Collection.Find(CreateEntityFilter(id)).FirstOrDefaultAsync(cancellationToken); + } + + public virtual TEntity Find(TPrimaryKey id) + { + return Collection.Find(CreateEntityFilter(id)).FirstOrDefault(); + } + + protected override FilterDefinition CreateEntityFilter(TEntity entity) + { + return Builders.Filter.Eq(e => e.Id, entity.Id); + } + + private static FilterDefinition CreateEntityFilter(TPrimaryKey id) + { + return Builders.Filter.Eq(e => e.Id, id); } } } \ No newline at end of file diff --git a/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/IMongoDbContextRegistrationOptionsBuilder.cs b/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/IMongoDbContextRegistrationOptionsBuilder.cs index 3e626b6558..6504639862 100644 --- a/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/IMongoDbContextRegistrationOptionsBuilder.cs +++ b/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/IMongoDbContextRegistrationOptionsBuilder.cs @@ -1,4 +1,3 @@ -using Volo.Abp.Data; using Volo.Abp.DependencyInjection; namespace Volo.Abp.MongoDB.DependencyInjection diff --git a/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/MongoDbRepositoryRegistrar.cs b/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/MongoDbRepositoryRegistrar.cs index 6d9d76be77..362f2bdb31 100644 --- a/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/MongoDbRepositoryRegistrar.cs +++ b/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/MongoDbRepositoryRegistrar.cs @@ -21,7 +21,7 @@ namespace Volo.Abp.MongoDB.DependencyInjection protected override Type GetRepositoryType(Type dbContextType, Type entityType) { - throw new NotImplementedException(); + return typeof(MongoDbRepository<,,>).MakeGenericType(dbContextType, entityType); } protected override Type GetRepositoryType(Type dbContextType, Type entityType, Type primaryKeyType) From 76fb510c3d38a76c49d39be50da45da8151087f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 26 Jan 2018 13:13:32 +0300 Subject: [PATCH 09/14] Renamed TPrimaryKey to TKey and documented entities. --- docs/Entities.md | 153 ++++++++++++++++++ .../ServiceCollectionRepositoryExtensions.cs | 4 +- .../Volo/Abp/Application/Dtos/EntityDto.cs | 10 +- .../Volo/Abp/Application/Dtos/IEntityDto.cs | 4 +- .../Services/AsyncCrudAppService.cs | 52 +++--- .../Application/Services/CrudAppService.cs | 52 +++--- .../Services/CrudAppServiceBase.cs | 12 +- .../Services/IAsyncCrudAppService.cs | 28 ++-- .../Application/Services/ICrudAppService.cs | 28 ++-- .../CommonDbContextRegistrationOptions.cs | 10 +- ...mmonDbContextRegistrationOptionsBuilder.cs | 4 +- .../Volo/Abp/Domain/Entities/AggregateRoot.cs | 4 +- .../Volo/Abp/Domain/Entities/Entity.cs | 14 +- .../Volo/Abp/Domain/Entities/EntityHelper.cs | 18 +-- .../Abp/Domain/Entities/IAggregateRoot.cs | 6 +- .../Volo/Abp/Domain/Entities/IEntity.cs | 8 +- .../Repositories/IQueryableRepository.cs | 4 +- .../Abp/Domain/Repositories/IRepository.cs | 16 +- .../Repositories/ISupportsExplicitLoading.cs | 4 +- .../Repositories/QueryableRepositoryBase.cs | 18 +-- .../Abp/Domain/Repositories/RepositoryBase.cs | 16 +- .../Repositories/RepositoryExtensions.cs | 28 ++-- .../Repositories/RepositoryRegistrarBase.cs | 2 +- .../EfCoreRepositoryExtensions.cs | 16 +- .../EntityFrameworkCore/EfCoreRepository.cs | 20 +-- .../EntityFrameworkCore/IEfCoreRepository.cs | 4 +- .../Repositories/MemoryDb/IMemoryDatabase.cs | 2 +- .../MemoryDb/IMemoryDbRepository.cs | 4 +- .../MemoryDb/InMemoryIdGenerator.cs | 16 +- .../Repositories/MemoryDb/MemoryDatabase.cs | 4 +- .../MemoryDb/MemoryDbRepository.cs | 22 +-- .../MemoryDbCoreRepositoryExtensions.cs | 16 +- .../MongoDB/IMongoDbRepository.cs | 4 +- .../Repositories/MongoDB/MongoDbRepository.cs | 18 +-- .../MongoDbCoreRepositoryExtensions.cs | 20 +-- .../RepositoryRegistration_Tests.cs | 20 +-- .../Volo/Abp/TestApp/Domain/Phone.cs | 72 +++++++++ 37 files changed, 479 insertions(+), 254 deletions(-) create mode 100644 docs/Entities.md diff --git a/docs/Entities.md b/docs/Entities.md new file mode 100644 index 0000000000..67e3856e7b --- /dev/null +++ b/docs/Entities.md @@ -0,0 +1,153 @@ +## Entities + +Entities are one of the core concepts of DDD (Domain Driven Design). Eric Evans describe it as "*An object that is not fundamentally defined by its attributes, but rather by a thread of continuity and identity*". + +An entity is generally mapped to a table in a relational database. + +### Entity Class + +Entities are derived from `Entity` class as shown below: + +```C# +public class Person : Entity +{ + public string Name { get; set; } + + public DateTime CreationTime { get; set; } + + public Person() + { + CreationTime = DateTime.Now; + } +} +``` + +> If you do not want derive your entity from the base `Entity` class, you can directly implement `IEntity` interface. + +`Entity` class just defines an `Id` property with the given primary **key type**, which is `int` in the sample above. It can be other types like `string`, `Guid`, `long` or whatever you need. + +Entity class also overrides the **equality** operator (==) to easily check if two entities are equal (they are equals if they are same entity type and their Ids are equals). + +#### Entities with Composite Keys + +Some entities may need to have **composite keys**. In that case, you can derive your entity from the non-generic `Entity` class. Example: + +````C# +public class UserRole : Entity +{ + public Guid UserId { get; set; } + + public Guid RoleId { get; set; } + + public DateTime CreationTime { get; set; } + + public Phone() + { + + } +} +```` + +For the example above, the composite key is composed of `UserId` and `RoleId`. For a relational database, it is the composite primary key of the related table. + +> Composite primary keys has some restriction with repositories. Since it has not known Id property, you can not use `IRepository` for these entities. However, you can always use `IRepository`. See repository documentation (TODO: link) for more. + +### AggregateRoot Class + +"*Aggregate is a pattern in Domain-Driven Design. A DDD aggregate is a cluster of domain objects that can be treated as a single unit. An example may be an order and its line-items, these will be separate objects, but it's useful to treat the order (together with its line items) as a single aggregate.*" (see the [full description](http://martinfowler.com/bliki/DDD_Aggregate.html)) + +`AggregateRoot` extends `Entity`. So, it also has an `Id` property by default. + +> Notice that ABP creates default repositories only for aggregate roots by default. However, it's possible to include all entities. See repository documentation (TODO: link) for more. + +ABP does not force you to use aggregate roots, you can only use the `Entity` class as defined before. However, if you want to implement DDD and want to create aggregate root classes, there are some best practices you can consider: + +* An aggregate root is responsible to preserve it's own integrity. This is also true for all entities, but aggregate root has responsibility for it's sub entities too. +* An aggregate root can be referenced by it's Id. Do not reference it by navigation property. +* An aggregate root is treated as a single unit. It's retrieved and updated as a single unit. It's generally considered as a transaction boundary. +* Work with sub-entities over the aggregate root, do not modify them independently. + +#### Aggregate Example + +This is a full sample of an aggregate root with a related sub-entity collection: + +````C# +public class Order : AggregateRoot +{ + public virtual string ReferenceNo { get; protected set; } + + public virtual int TotalItemCount { get; protected set; } + + public virtual DateTime CreationTime { get; protected set; } + + public virtual List OrderLines { get; protected set; } + + protected Order() + { + + } + + public Order(Guid id, string referenceNo) + { + Id = id; + ReferenceNo = referenceNo; + OrderLines = new List(); + } + + public void AddProduct(Guid productId, int count) + { + if (count <= 0) + { + throw new ArgumentException( + "You can not add zero or negative count of products!", + nameof(count) + ); + } + + var existingLine = OrderLines.FirstOrDefault(ol => ol.ProductId == productId); + + if (existingLine == null) + { + OrderLines.Add(new OrderLine(this.Id, productId, count)); + } + else + { + existingLine.ChangeCount(existingLine.Count + count); + } + + TotalItemCount += count; + } +} + +public class OrderLine : Entity +{ + public virtual Guid OrderId { get; protected set; } + + public virtual Guid ProductId { get; protected set; } + + public virtual int Count { get; protected set; } + + protected OrderLine() + { + + } + + internal OrderLine(Guid orderId, Guid productId, int count) + { + OrderId = orderId; + ProductId = productId; + Count = count; + } + + internal void ChangeCount(int newCount) + { + Count = newCount; + } +} +```` + +In this example; + +* `Order` is an **aggregate root entity** with `Guid` type `Id` property. It has a collection of `OrderLine` entities. `OrderLine` is another entity with a composite primary key (`OrderLine` and ` ProductId`). +* ... + diff --git a/src/Volo.Abp.Ddd/Microsoft/Extensions/DependencyInjection/ServiceCollectionRepositoryExtensions.cs b/src/Volo.Abp.Ddd/Microsoft/Extensions/DependencyInjection/ServiceCollectionRepositoryExtensions.cs index 1e75094169..e6203386ae 100644 --- a/src/Volo.Abp.Ddd/Microsoft/Extensions/DependencyInjection/ServiceCollectionRepositoryExtensions.cs +++ b/src/Volo.Abp.Ddd/Microsoft/Extensions/DependencyInjection/ServiceCollectionRepositoryExtensions.cs @@ -31,14 +31,14 @@ namespace Microsoft.Extensions.DependencyInjection if (primaryKeyType != null) { - //IRepository + //IRepository var repositoryInterface = typeof(IRepository<,>).MakeGenericType(entityType, primaryKeyType); if (repositoryInterface.GetTypeInfo().IsAssignableFrom(repositoryImplementationType)) { services.TryAddTransient(repositoryInterface, repositoryImplementationType); } - //IQueryableRepository + //IQueryableRepository var queryableRepositoryInterface = typeof(IQueryableRepository<,>).MakeGenericType(entityType, primaryKeyType); if (queryableRepositoryInterface.GetTypeInfo().IsAssignableFrom(repositoryImplementationType)) { diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Application/Dtos/EntityDto.cs b/src/Volo.Abp.Ddd/Volo/Abp/Application/Dtos/EntityDto.cs index aaf4e1da9a..76407cf8a5 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Application/Dtos/EntityDto.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Application/Dtos/EntityDto.cs @@ -8,15 +8,15 @@ namespace Volo.Abp.Application.Dtos } } - public class EntityDto : EntityDto, IEntityDto + public class EntityDto : EntityDto, IEntityDto { /// /// Id of the entity. /// - public TPrimaryKey Id { get; set; } + public TKey Id { get; set; } /// - /// Creates a new object. + /// Creates a new object. /// public EntityDto() { @@ -24,10 +24,10 @@ namespace Volo.Abp.Application.Dtos } /// - /// Creates a new object. + /// Creates a new object. /// /// Id of the entity - public EntityDto(TPrimaryKey id) + public EntityDto(TKey id) { Id = id; } diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Application/Dtos/IEntityDto.cs b/src/Volo.Abp.Ddd/Volo/Abp/Application/Dtos/IEntityDto.cs index 00e0f98cdb..1f774e50d1 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Application/Dtos/IEntityDto.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Application/Dtos/IEntityDto.cs @@ -5,8 +5,8 @@ } - public interface IEntityDto : IEntityDto + public interface IEntityDto : IEntityDto { - TPrimaryKey Id { get; set; } + TKey Id { get; set; } } } \ No newline at end of file diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/AsyncCrudAppService.cs b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/AsyncCrudAppService.cs index 2e631d2f4c..bbd4a8eaeb 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/AsyncCrudAppService.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/AsyncCrudAppService.cs @@ -7,59 +7,59 @@ using Volo.Abp.Linq; namespace Volo.Abp.Application.Services { - public abstract class AsyncCrudAppService - : AsyncCrudAppService - where TEntity : class, IEntity - where TEntityDto : IEntityDto + public abstract class AsyncCrudAppService + : AsyncCrudAppService + where TEntity : class, IEntity + where TEntityDto : IEntityDto { - protected AsyncCrudAppService(IQueryableRepository repository) + protected AsyncCrudAppService(IQueryableRepository repository) : base(repository) { } } - public abstract class AsyncCrudAppService - : AsyncCrudAppService - where TEntity : class, IEntity - where TEntityDto : IEntityDto + public abstract class AsyncCrudAppService + : AsyncCrudAppService + where TEntity : class, IEntity + where TEntityDto : IEntityDto { - protected AsyncCrudAppService(IQueryableRepository repository) + protected AsyncCrudAppService(IQueryableRepository repository) : base(repository) { } } - public abstract class AsyncCrudAppService - : AsyncCrudAppService + public abstract class AsyncCrudAppService + : AsyncCrudAppService where TGetAllInput : IPagedAndSortedResultRequest - where TEntity : class, IEntity - where TEntityDto : IEntityDto - where TCreateInput : IEntityDto + where TEntity : class, IEntity + where TEntityDto : IEntityDto + where TCreateInput : IEntityDto { - protected AsyncCrudAppService(IQueryableRepository repository) + protected AsyncCrudAppService(IQueryableRepository repository) : base(repository) { } } - public abstract class AsyncCrudAppService - : CrudAppServiceBase, - IAsyncCrudAppService - where TEntity : class, IEntity - where TEntityDto : IEntityDto + public abstract class AsyncCrudAppService + : CrudAppServiceBase, + IAsyncCrudAppService + where TEntity : class, IEntity + where TEntityDto : IEntityDto { public IAsyncQueryableExecuter AsyncQueryableExecuter { get; set; } - protected AsyncCrudAppService(IQueryableRepository repository) + protected AsyncCrudAppService(IQueryableRepository repository) :base(repository) { AsyncQueryableExecuter = DefaultAsyncQueryableExecuter.Instance; } - public virtual async Task GetAsync(TPrimaryKey id) + public virtual async Task GetAsync(TKey id) { CheckGetPermission(); @@ -98,7 +98,7 @@ namespace Volo.Abp.Application.Services return MapToEntityDto(entity); } - public virtual async Task UpdateAsync(TPrimaryKey id, TUpdateInput input) + public virtual async Task UpdateAsync(TKey id, TUpdateInput input) { CheckUpdatePermission(); @@ -112,14 +112,14 @@ namespace Volo.Abp.Application.Services return MapToEntityDto(entity); } - public virtual Task DeleteAsync(TPrimaryKey id) + public virtual Task DeleteAsync(TKey id) { CheckDeletePermission(); return Repository.DeleteAsync(id); } - protected virtual Task GetEntityByIdAsync(TPrimaryKey id) + protected virtual Task GetEntityByIdAsync(TKey id) { return Repository.GetAsync(id); } diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppService.cs b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppService.cs index cec074f909..367552dba0 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppService.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppService.cs @@ -5,56 +5,56 @@ using Volo.Abp.Domain.Repositories; namespace Volo.Abp.Application.Services { - public abstract class CrudAppService - : CrudAppService - where TEntity : class, IEntity - where TEntityDto : IEntityDto + public abstract class CrudAppService + : CrudAppService + where TEntity : class, IEntity + where TEntityDto : IEntityDto { - protected CrudAppService(IQueryableRepository repository) + protected CrudAppService(IQueryableRepository repository) : base(repository) { } } - public abstract class CrudAppService - : CrudAppService - where TEntity : class, IEntity - where TEntityDto : IEntityDto + public abstract class CrudAppService + : CrudAppService + where TEntity : class, IEntity + where TEntityDto : IEntityDto { - protected CrudAppService(IQueryableRepository repository) + protected CrudAppService(IQueryableRepository repository) : base(repository) { } } - public abstract class CrudAppService - : CrudAppService - where TEntity : class, IEntity - where TEntityDto : IEntityDto - where TCreateInput : IEntityDto + public abstract class CrudAppService + : CrudAppService + where TEntity : class, IEntity + where TEntityDto : IEntityDto + where TCreateInput : IEntityDto { - protected CrudAppService(IQueryableRepository repository) + protected CrudAppService(IQueryableRepository repository) : base(repository) { } } - public abstract class CrudAppService - : CrudAppServiceBase, - ICrudAppService - where TEntity : class, IEntity - where TEntityDto : IEntityDto + public abstract class CrudAppService + : CrudAppServiceBase, + ICrudAppService + where TEntity : class, IEntity + where TEntityDto : IEntityDto { - protected CrudAppService(IQueryableRepository repository) + protected CrudAppService(IQueryableRepository repository) : base(repository) { } - public virtual TEntityDto Get(TPrimaryKey id) + public virtual TEntityDto Get(TKey id) { CheckGetPermission(); @@ -93,7 +93,7 @@ namespace Volo.Abp.Application.Services return MapToEntityDto(entity); } - public virtual TEntityDto Update(TPrimaryKey id, TUpdateInput input) + public virtual TEntityDto Update(TKey id, TUpdateInput input) { CheckUpdatePermission(); @@ -105,14 +105,14 @@ namespace Volo.Abp.Application.Services return MapToEntityDto(entity); } - public virtual void Delete(TPrimaryKey id) + public virtual void Delete(TKey id) { CheckDeletePermission(); Repository.Delete(id); } - protected virtual TEntity GetEntityById(TPrimaryKey id) + protected virtual TEntity GetEntityById(TKey id) { return Repository.Get(id); } diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppServiceBase.cs b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppServiceBase.cs index ec04a532ab..b9ad25a574 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppServiceBase.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppServiceBase.cs @@ -11,11 +11,11 @@ namespace Volo.Abp.Application.Services /// This is a common base class for CrudAppService and AsyncCrudAppService classes. /// Inherit either from CrudAppService or AsyncCrudAppService, not from this class. /// - public abstract class CrudAppServiceBase : ApplicationService - where TEntity : class, IEntity - where TEntityDto : IEntityDto + public abstract class CrudAppServiceBase : ApplicationService + where TEntity : class, IEntity + where TEntityDto : IEntityDto { - protected IQueryableRepository Repository { get; } + protected IQueryableRepository Repository { get; } protected virtual string GetPermissionName { get; set; } @@ -27,7 +27,7 @@ namespace Volo.Abp.Application.Services protected virtual string DeletePermissionName { get; set; } - protected CrudAppServiceBase(IQueryableRepository repository) + protected CrudAppServiceBase(IQueryableRepository repository) { Repository = repository; } @@ -119,7 +119,7 @@ namespace Volo.Abp.Application.Services } /// - /// Sets Id value for the entity if is . + /// Sets Id value for the entity if is . /// It's used while creating a new entity. /// protected virtual void SetIdForGuids(TEntity entity) diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/IAsyncCrudAppService.cs b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/IAsyncCrudAppService.cs index 37c8293df4..4f97c49ae0 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/IAsyncCrudAppService.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/IAsyncCrudAppService.cs @@ -3,39 +3,39 @@ using Volo.Abp.Application.Dtos; namespace Volo.Abp.Application.Services { - public interface IAsyncCrudAppService - : IAsyncCrudAppService - where TEntityDto : IEntityDto + public interface IAsyncCrudAppService + : IAsyncCrudAppService + where TEntityDto : IEntityDto { } - public interface IAsyncCrudAppService - : IAsyncCrudAppService - where TEntityDto : IEntityDto + public interface IAsyncCrudAppService + : IAsyncCrudAppService + where TEntityDto : IEntityDto { } - public interface IAsyncCrudAppService - : IAsyncCrudAppService - where TEntityDto : IEntityDto + public interface IAsyncCrudAppService + : IAsyncCrudAppService + where TEntityDto : IEntityDto { } - public interface IAsyncCrudAppService + public interface IAsyncCrudAppService : IApplicationService - where TEntityDto : IEntityDto + where TEntityDto : IEntityDto { - Task GetAsync(TPrimaryKey id); + Task GetAsync(TKey id); Task> GetListAsync(TGetListInput input); Task CreateAsync(TCreateInput input); - Task UpdateAsync(TPrimaryKey id, TUpdateInput input); + Task UpdateAsync(TKey id, TUpdateInput input); - Task DeleteAsync(TPrimaryKey id); + Task DeleteAsync(TKey id); } } diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/ICrudAppService.cs b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/ICrudAppService.cs index 9400f8825c..9f06c63aea 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/ICrudAppService.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/ICrudAppService.cs @@ -2,39 +2,39 @@ using Volo.Abp.Application.Dtos; namespace Volo.Abp.Application.Services { - public interface ICrudAppService - : ICrudAppService - where TEntityDto : IEntityDto + public interface ICrudAppService + : ICrudAppService + where TEntityDto : IEntityDto { } - public interface ICrudAppService - : ICrudAppService - where TEntityDto : IEntityDto + public interface ICrudAppService + : ICrudAppService + where TEntityDto : IEntityDto { } - public interface ICrudAppService - : ICrudAppService - where TEntityDto : IEntityDto + public interface ICrudAppService + : ICrudAppService + where TEntityDto : IEntityDto { } - public interface ICrudAppService + public interface ICrudAppService : IApplicationService - where TEntityDto : IEntityDto + where TEntityDto : IEntityDto { - TEntityDto Get(TPrimaryKey id); + TEntityDto Get(TKey id); PagedResultDto GetAll(TGetListInput input); TEntityDto Create(TCreateInput input); - TEntityDto Update(TPrimaryKey id, TUpdateInput input); + TEntityDto Update(TKey id, TUpdateInput input); - void Delete(TPrimaryKey id); + void Delete(TKey id); } } diff --git a/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/CommonDbContextRegistrationOptions.cs b/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/CommonDbContextRegistrationOptions.cs index e195a348bf..917e9bd57a 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/CommonDbContextRegistrationOptions.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/CommonDbContextRegistrationOptions.cs @@ -19,7 +19,7 @@ namespace Volo.Abp.DependencyInjection public Type DefaultRepositoryImplementationType { get; private set; } - public Type DefaultRepositoryImplementationTypeWithoutPrimaryKey { get; private set; } + public Type DefaultRepositoryImplementationTypeWithouTKey { get; private set; } public bool RegisterDefaultRepositories { get; private set; } @@ -27,7 +27,7 @@ namespace Volo.Abp.DependencyInjection public Dictionary CustomRepositories { get; } - public bool SpecifiedDefaultRepositoryTypes => DefaultRepositoryImplementationType != null && DefaultRepositoryImplementationTypeWithoutPrimaryKey != null; + public bool SpecifiedDefaultRepositoryTypes => DefaultRepositoryImplementationType != null && DefaultRepositoryImplementationTypeWithouTKey != null; protected CommonDbContextRegistrationOptions(Type originalDbContextType) { @@ -88,14 +88,14 @@ namespace Volo.Abp.DependencyInjection public ICommonDbContextRegistrationOptionsBuilder SetDefaultRepositoryClasses( Type repositoryImplementationType, - Type repositoryImplementationTypeWithoutPrimaryKey + Type repositoryImplementationTypeWithouTKey ) { Check.NotNull(repositoryImplementationType, nameof(repositoryImplementationType)); - Check.NotNull(repositoryImplementationTypeWithoutPrimaryKey, nameof(repositoryImplementationTypeWithoutPrimaryKey)); + Check.NotNull(repositoryImplementationTypeWithouTKey, nameof(repositoryImplementationTypeWithouTKey)); DefaultRepositoryImplementationType = repositoryImplementationType; - DefaultRepositoryImplementationTypeWithoutPrimaryKey = repositoryImplementationTypeWithoutPrimaryKey; + DefaultRepositoryImplementationTypeWithouTKey = repositoryImplementationTypeWithouTKey; return this; } diff --git a/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/ICommonDbContextRegistrationOptionsBuilder.cs b/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/ICommonDbContextRegistrationOptionsBuilder.cs index c68b544ce2..837f7bc110 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/ICommonDbContextRegistrationOptionsBuilder.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/ICommonDbContextRegistrationOptionsBuilder.cs @@ -48,9 +48,9 @@ namespace Volo.Abp.DependencyInjection /// Uses given class(es) for default repositories. /// /// Repository implementation type - /// Repository implementation type (without primary key) + /// Repository implementation type (without primary key) /// - ICommonDbContextRegistrationOptionsBuilder SetDefaultRepositoryClasses([NotNull] Type repositoryImplementationType, [NotNull] Type repositoryImplementationTypeWithoutPrimaryKey); + ICommonDbContextRegistrationOptionsBuilder SetDefaultRepositoryClasses([NotNull] Type repositoryImplementationType, [NotNull] Type repositoryImplementationTypeWithouTKey); /// /// Replaces given DbContext type with this DbContext type. diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/AggregateRoot.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/AggregateRoot.cs index 65853729d6..a2b233406f 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/AggregateRoot.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/AggregateRoot.cs @@ -7,8 +7,8 @@ } - /// - public abstract class AggregateRoot : Entity, IAggregateRoot + /// + public abstract class AggregateRoot : Entity, IAggregateRoot { } diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs index 185aad9767..007442f781 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs @@ -12,16 +12,16 @@ namespace Volo.Abp.Domain.Entities } } - /// - public abstract class Entity : Entity, IEntity + /// + public abstract class Entity : Entity, IEntity { /// - public virtual TPrimaryKey Id { get; set; } + public virtual TKey Id { get; set; } /// public override bool Equals(object obj) { - if (obj == null || !(obj is Entity)) + if (obj == null || !(obj is Entity)) { return false; } @@ -33,7 +33,7 @@ namespace Volo.Abp.Domain.Entities } //Transient objects are not considered as equal - var other = (Entity)obj; + var other = (Entity)obj; if (EntityHelper.IsTransient(this) && EntityHelper.IsTransient(other)) { return false; @@ -61,7 +61,7 @@ namespace Volo.Abp.Domain.Entities return Id.GetHashCode(); } - public static bool operator ==(Entity left, Entity right) + public static bool operator ==(Entity left, Entity right) { if (Equals(left, null)) { @@ -71,7 +71,7 @@ namespace Volo.Abp.Domain.Entities return left.Equals(right); } - public static bool operator !=(Entity left, Entity right) + public static bool operator !=(Entity left, Entity right) { return !(left == right); } diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/EntityHelper.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/EntityHelper.cs index 3dee5b0ee5..18f6f2a8e9 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/EntityHelper.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/EntityHelper.cs @@ -16,20 +16,20 @@ namespace Volo.Abp.Domain.Entities return typeof(IEntity).IsAssignableFrom(type); } - public static bool IsTransient(IEntity entity) // TODO: Completely remove IsTransient + public static bool IsTransient(IEntity entity) // TODO: Completely remove IsTransient { - if (EqualityComparer.Default.Equals(entity.Id, default)) + if (EqualityComparer.Default.Equals(entity.Id, default)) { return true; } //Workaround for EF Core since it sets int/long to min value when attaching to dbcontext - if (typeof(TPrimaryKey) == typeof(int)) + if (typeof(TKey) == typeof(int)) { return Convert.ToInt32(entity.Id) <= 0; } - if (typeof(TPrimaryKey) == typeof(long)) + if (typeof(TKey) == typeof(long)) { return Convert.ToInt64(entity.Id) <= 0; } @@ -39,7 +39,7 @@ namespace Volo.Abp.Domain.Entities /// /// Tries to find the primary key type of the given entity type. - /// May return null if given type does not implement + /// May return null if given type does not implement /// [CanBeNull] public static Type FindPrimaryKeyType() @@ -50,7 +50,7 @@ namespace Volo.Abp.Domain.Entities /// /// Tries to find the primary key type of the given entity type. - /// May return null if given type does not implement + /// May return null if given type does not implement /// [CanBeNull] public static Type FindPrimaryKeyType([NotNull] Type entityType) @@ -71,13 +71,13 @@ namespace Volo.Abp.Domain.Entities return null; } - public static Expression> CreateEqualityExpressionForId(TPrimaryKey id) - where TEntity : IEntity + public static Expression> CreateEqualityExpressionForId(TKey id) + where TEntity : IEntity { var lambdaParam = Expression.Parameter(typeof(TEntity)); var lambdaBody = Expression.Equal( Expression.PropertyOrField(lambdaParam, "Id"), - Expression.Constant(id, typeof(TPrimaryKey)) + Expression.Constant(id, typeof(TKey)) ); return Expression.Lambda>(lambdaBody, lambdaParam); diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IAggregateRoot.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IAggregateRoot.cs index 5050df0cca..bdb436c51d 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IAggregateRoot.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IAggregateRoot.cs @@ -2,7 +2,7 @@ { /// /// Defines an aggregate root. It's primary key may not be "Id" or it may have a composite primary key. - /// Use where possible for better integration to repositories and other structures in the framework. + /// Use where possible for better integration to repositories and other structures in the framework. /// public interface IAggregateRoot : IEntity { @@ -12,8 +12,8 @@ /// /// Defines an aggregate root with a single primary key with "Id" property. /// - /// Type of the primary key of the entity - public interface IAggregateRoot : IEntity, IAggregateRoot + /// Type of the primary key of the entity + public interface IAggregateRoot : IEntity, IAggregateRoot { } diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs index a2f17e3f82..4cc25837d1 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs @@ -2,7 +2,7 @@ { /// /// Defines an entity. It's primary key may not be "Id" or it mah have a composite primary key. - /// Use where possible for better integration to repositories and other structures in the framework. + /// Use where possible for better integration to repositories and other structures in the framework. /// public interface IEntity { @@ -12,12 +12,12 @@ /// /// Defines an entity with a single primary key with "Id" property. /// - /// Type of the primary key of the entity - public interface IEntity : IEntity + /// Type of the primary key of the entity + public interface IEntity : IEntity { /// /// Unique identifier for this entity. /// - TPrimaryKey Id { get; set; } + TKey Id { get; set; } } } diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IQueryableRepository.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IQueryableRepository.cs index 6a0e35e4ed..52014849ad 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IQueryableRepository.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IQueryableRepository.cs @@ -31,8 +31,8 @@ namespace Volo.Abp.Domain.Repositories Task DeleteAsync([NotNull] Expression> predicate, CancellationToken cancellationToken = default); } - public interface IQueryableRepository : IQueryableRepository, IRepository - where TEntity : class, IEntity + public interface IQueryableRepository : IQueryableRepository, IRepository + where TEntity : class, IEntity { } } \ No newline at end of file diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs index 1b70ff510f..94521c7628 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs @@ -69,8 +69,8 @@ namespace Volo.Abp.Domain.Repositories Task DeleteAsync([NotNull] TEntity entity, CancellationToken cancellationToken = default); //TODO: Return true if deleted } - public interface IRepository : IRepository - where TEntity : class, IEntity + public interface IRepository : IRepository + where TEntity : class, IEntity { /// /// Gets an entity with given primary key. @@ -79,7 +79,7 @@ namespace Volo.Abp.Domain.Repositories /// Primary key of the entity to get /// Entity [NotNull] - TEntity Get(TPrimaryKey id); + TEntity Get(TKey id); /// /// Gets an entity with given primary key. @@ -89,7 +89,7 @@ namespace Volo.Abp.Domain.Repositories /// A to observe while waiting for the task to complete. /// Entity [NotNull] - Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default); + Task GetAsync(TKey id, CancellationToken cancellationToken = default); /// /// Gets an entity with given primary key or null if not found. @@ -97,7 +97,7 @@ namespace Volo.Abp.Domain.Repositories /// Primary key of the entity to get /// Entity or null [CanBeNull] - TEntity Find(TPrimaryKey id); + TEntity Find(TKey id); /// /// Gets an entity with given primary key or null if not found. @@ -105,19 +105,19 @@ namespace Volo.Abp.Domain.Repositories /// Primary key of the entity to get /// A to observe while waiting for the task to complete. /// Entity or null - Task FindAsync(TPrimaryKey id, CancellationToken cancellationToken = default); + Task FindAsync(TKey id, CancellationToken cancellationToken = default); /// /// Deletes an entity by primary key. /// /// Primary key of the entity - void Delete(TPrimaryKey id); //TODO: Return true if deleted + void Delete(TKey id); //TODO: Return true if deleted /// /// Deletes an entity by primary key. /// /// A to observe while waiting for the task to complete. /// Primary key of the entity - Task DeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default); //TODO: Return true if deleted + Task DeleteAsync(TKey id, CancellationToken cancellationToken = default); //TODO: Return true if deleted } } diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/ISupportsExplicitLoading.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/ISupportsExplicitLoading.cs index 9b4a98863c..79eb68daf6 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/ISupportsExplicitLoading.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/ISupportsExplicitLoading.cs @@ -7,8 +7,8 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.Domain.Repositories { - public interface ISupportsExplicitLoading - where TEntity : class, IEntity + public interface ISupportsExplicitLoading + where TEntity : class, IEntity { Task EnsureCollectionLoadedAsync( TEntity entity, diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs index 00ef2c07be..f7000714e0 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs @@ -68,15 +68,15 @@ namespace Volo.Abp.Domain.Repositories } } - public abstract class QueryableRepositoryBase : QueryableRepositoryBase, IQueryableRepository - where TEntity : class, IEntity + public abstract class QueryableRepositoryBase : QueryableRepositoryBase, IQueryableRepository + where TEntity : class, IEntity { - public virtual TEntity Find(TPrimaryKey id) + public virtual TEntity Find(TKey id) { - return GetQueryable().FirstOrDefault(EntityHelper.CreateEqualityExpressionForId(id)); + return GetQueryable().FirstOrDefault(EntityHelper.CreateEqualityExpressionForId(id)); } - public virtual TEntity Get(TPrimaryKey id) + public virtual TEntity Get(TKey id) { var entity = Find(id); @@ -88,17 +88,17 @@ namespace Volo.Abp.Domain.Repositories return entity; } - public virtual Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + public virtual Task GetAsync(TKey id, CancellationToken cancellationToken = default) { return Task.FromResult(Get(id)); } - public virtual Task FindAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + public virtual Task FindAsync(TKey id, CancellationToken cancellationToken = default) { return Task.FromResult(Find(id)); } - public virtual void Delete(TPrimaryKey id) + public virtual void Delete(TKey id) { var entity = Find(id); if (entity == null) @@ -109,7 +109,7 @@ namespace Volo.Abp.Domain.Repositories Delete(entity); } - public virtual Task DeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + public virtual Task DeleteAsync(TKey id, CancellationToken cancellationToken = default) { Delete(id); return Task.CompletedTask; diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs index bc52a145a8..953b967c2c 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs @@ -43,10 +43,10 @@ namespace Volo.Abp.Domain.Repositories } } - public abstract class RepositoryBase : RepositoryBase, IRepository - where TEntity : class, IEntity + public abstract class RepositoryBase : RepositoryBase, IRepository + where TEntity : class, IEntity { - public virtual TEntity Get(TPrimaryKey id) + public virtual TEntity Get(TKey id) { var entity = Find(id); @@ -58,19 +58,19 @@ namespace Volo.Abp.Domain.Repositories return entity; } - public virtual Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + public virtual Task GetAsync(TKey id, CancellationToken cancellationToken = default) { return Task.FromResult(Get(id)); } - public abstract TEntity Find(TPrimaryKey id); + public abstract TEntity Find(TKey id); - public virtual Task FindAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + public virtual Task FindAsync(TKey id, CancellationToken cancellationToken = default) { return Task.FromResult(Find(id)); } - public virtual void Delete(TPrimaryKey id) + public virtual void Delete(TKey id) { var entity = Find(id); if (entity == null) @@ -81,7 +81,7 @@ namespace Volo.Abp.Domain.Repositories Delete(entity); } - public virtual Task DeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + public virtual Task DeleteAsync(TKey id, CancellationToken cancellationToken = default) { Delete(id); return Task.CompletedTask; diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryExtensions.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryExtensions.cs index 3c9a503780..ccb4cd2c60 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryExtensions.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryExtensions.cs @@ -11,55 +11,55 @@ namespace Volo.Abp.Domain.Repositories { public static class RepositoryExtensions { - public static async Task EnsureCollectionLoadedAsync( - this IRepository repository, + public static async Task EnsureCollectionLoadedAsync( + this IRepository repository, TEntity entity, Expression>> propertyExpression, CancellationToken cancellationToken = default ) - where TEntity : class, IEntity + where TEntity : class, IEntity where TProperty : class { - var repo = ProxyHelper.UnProxy(repository) as ISupportsExplicitLoading; + var repo = ProxyHelper.UnProxy(repository) as ISupportsExplicitLoading; if (repo != null) { await repo.EnsureCollectionLoadedAsync(entity, propertyExpression, cancellationToken); } } - public static void EnsureCollectionLoaded( - this IRepository repository, + public static void EnsureCollectionLoaded( + this IRepository repository, TEntity entity, Expression>> propertyExpression ) - where TEntity : class, IEntity + where TEntity : class, IEntity where TProperty : class { AsyncHelper.RunSync(() => repository.EnsureCollectionLoadedAsync(entity, propertyExpression)); } - public static async Task EnsurePropertyLoadedAsync( - this IRepository repository, + public static async Task EnsurePropertyLoadedAsync( + this IRepository repository, TEntity entity, Expression> propertyExpression, CancellationToken cancellationToken = default ) - where TEntity : class, IEntity + where TEntity : class, IEntity where TProperty : class { - var repo = ProxyHelper.UnProxy(repository) as ISupportsExplicitLoading; + var repo = ProxyHelper.UnProxy(repository) as ISupportsExplicitLoading; if (repo != null) { await repo.EnsurePropertyLoadedAsync(entity, propertyExpression, cancellationToken); } } - public static void EnsurePropertyLoaded( - this IRepository repository, + public static void EnsurePropertyLoaded( + this IRepository repository, TEntity entity, Expression> propertyExpression ) - where TEntity : class, IEntity + where TEntity : class, IEntity where TProperty : class { AsyncHelper.RunSync(() => repository.EnsurePropertyLoadedAsync(entity, propertyExpression)); diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryRegistrarBase.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryRegistrarBase.cs index 9b5510de89..addae8de35 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryRegistrarBase.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryRegistrarBase.cs @@ -57,7 +57,7 @@ namespace Volo.Abp.Domain.Repositories if (primaryKeyType == null) { return Options.SpecifiedDefaultRepositoryTypes - ? Options.DefaultRepositoryImplementationTypeWithoutPrimaryKey.MakeGenericType(entityType) + ? Options.DefaultRepositoryImplementationTypeWithouTKey.MakeGenericType(entityType) : GetRepositoryType(Options.DefaultRepositoryDbContextType, entityType); } diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EfCoreRepositoryExtensions.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EfCoreRepositoryExtensions.cs index 84471504f7..33f34a79bf 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EfCoreRepositoryExtensions.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EfCoreRepositoryExtensions.cs @@ -7,25 +7,25 @@ namespace Volo.Abp.Domain.Repositories { public static class EfCoreRepositoryExtensions { - public static DbContext GetDbContext(this IRepository repository) - where TEntity : class, IEntity + public static DbContext GetDbContext(this IRepository repository) + where TEntity : class, IEntity { return repository.ToEfCoreRepository().DbContext; } - public static DbSet GetDbSet(this IRepository repository) - where TEntity : class, IEntity + public static DbSet GetDbSet(this IRepository repository) + where TEntity : class, IEntity { return repository.ToEfCoreRepository().DbSet; } - public static IEfCoreRepository ToEfCoreRepository(this IRepository repository) - where TEntity : class, IEntity + public static IEfCoreRepository ToEfCoreRepository(this IRepository repository) + where TEntity : class, IEntity { - var efCoreRepository = repository as IEfCoreRepository; + var efCoreRepository = repository as IEfCoreRepository; if (efCoreRepository == null) { - throw new ArgumentException("Given repository does not implement " + typeof(IEfCoreRepository).AssemblyQualifiedName, nameof(repository)); + throw new ArgumentException("Given repository does not implement " + typeof(IEfCoreRepository).AssemblyQualifiedName, nameof(repository)); } return efCoreRepository; diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs index 9bd7245b7a..322096084d 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs @@ -95,12 +95,12 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore } } - public class EfCoreRepository : EfCoreRepository, - IEfCoreRepository, - ISupportsExplicitLoading + public class EfCoreRepository : EfCoreRepository, + IEfCoreRepository, + ISupportsExplicitLoading where TDbContext : IEfCoreDbContext - where TEntity : class, IEntity + where TEntity : class, IEntity { public EfCoreRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) @@ -108,7 +108,7 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore } - public TEntity Get(TPrimaryKey id) + public TEntity Get(TKey id) { var entity = Find(id); @@ -120,7 +120,7 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore return entity; } - public virtual async Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + public virtual async Task GetAsync(TKey id, CancellationToken cancellationToken = default) { var entity = await FindAsync(id, GetCancellationToken(cancellationToken)); @@ -132,17 +132,17 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore return entity; } - public virtual TEntity Find(TPrimaryKey id) + public virtual TEntity Find(TKey id) { return DbSet.Find(id); } - public virtual Task FindAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + public virtual Task FindAsync(TKey id, CancellationToken cancellationToken = default) { return DbSet.FindAsync(new object[] { id }, GetCancellationToken(cancellationToken)); } - public virtual void Delete(TPrimaryKey id) + public virtual void Delete(TKey id) { var entity = Find(id); if (entity == null) @@ -153,7 +153,7 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore Delete(entity); } - public virtual Task DeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + public virtual Task DeleteAsync(TKey id, CancellationToken cancellationToken = default) { Delete(id); return Task.CompletedTask; diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs index 8232f02fcd..b0354df4c9 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs @@ -11,8 +11,8 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore DbSet DbSet { get; } } - public interface IEfCoreRepository : IEfCoreRepository, IQueryableRepository - where TEntity : class, IEntity + public interface IEfCoreRepository : IEfCoreRepository, IQueryableRepository + where TEntity : class, IEntity { } diff --git a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/IMemoryDatabase.cs b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/IMemoryDatabase.cs index 7cbaf15e70..1e6cd6f54c 100644 --- a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/IMemoryDatabase.cs +++ b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/IMemoryDatabase.cs @@ -6,6 +6,6 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb { List Collection(); - TPrimaryKey GenerateNextId(); + TKey GenerateNextId(); } } \ No newline at end of file diff --git a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/IMemoryDbRepository.cs b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/IMemoryDbRepository.cs index 8d43180088..6b89208130 100644 --- a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/IMemoryDbRepository.cs +++ b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/IMemoryDbRepository.cs @@ -11,8 +11,8 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb List Collection { get; } } - public interface IMemoryDbRepository : IMemoryDbRepository, IQueryableRepository - where TEntity : class, IEntity + public interface IMemoryDbRepository : IMemoryDbRepository, IQueryableRepository + where TEntity : class, IEntity { } diff --git a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/InMemoryIdGenerator.cs b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/InMemoryIdGenerator.cs index 1741d2cc02..467fff5bc5 100644 --- a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/InMemoryIdGenerator.cs +++ b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/InMemoryIdGenerator.cs @@ -8,24 +8,24 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb private int _lastInt; private long _lastLong; - public TPrimaryKey GenerateNext() + public TKey GenerateNext() { - if (typeof(TPrimaryKey) == typeof(Guid)) + if (typeof(TKey) == typeof(Guid)) { - return (TPrimaryKey)(object)Guid.NewGuid(); + return (TKey)(object)Guid.NewGuid(); } - if (typeof(TPrimaryKey) == typeof(int)) + if (typeof(TKey) == typeof(int)) { - return (TPrimaryKey)(object)Interlocked.Increment(ref _lastInt); + return (TKey)(object)Interlocked.Increment(ref _lastInt); } - if (typeof(TPrimaryKey) == typeof(long)) + if (typeof(TKey) == typeof(long)) { - return (TPrimaryKey)(object)Interlocked.Increment(ref _lastLong); + return (TKey)(object)Interlocked.Increment(ref _lastLong); } - throw new AbpException("Not supported PrimaryKey type: " + typeof(TPrimaryKey).FullName); + throw new AbpException("Not supported PrimaryKey type: " + typeof(TKey).FullName); } } } \ No newline at end of file diff --git a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDatabase.cs b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDatabase.cs index 332138eae2..212c151087 100644 --- a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDatabase.cs +++ b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDatabase.cs @@ -21,11 +21,11 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb return _sets.GetOrAdd(typeof(TEntity), _ => new List()) as List; } - public TPrimaryKey GenerateNextId() + public TKey GenerateNextId() { return _idGenerators .GetOrAdd(typeof(TEntity), () => new InMemoryIdGenerator()) - .GenerateNext(); + .GenerateNext(); } } } \ No newline at end of file diff --git a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs index acd37028a4..72e84d126f 100644 --- a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs +++ b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs @@ -45,9 +45,9 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb } } - public class MemoryDbRepository : MemoryDbRepository, IMemoryDbRepository + public class MemoryDbRepository : MemoryDbRepository, IMemoryDbRepository where TMemoryDbContext : MemoryDbContext - where TEntity : class, IEntity + where TEntity : class, IEntity { public MemoryDbRepository(IMemoryDatabaseProvider databaseProvider) : base(databaseProvider) @@ -62,21 +62,21 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb private void SetIdIfNeeded(TEntity entity) { - if (typeof(TPrimaryKey) == typeof(int) || typeof(TPrimaryKey) == typeof(long) || typeof(TPrimaryKey) == typeof(Guid)) + if (typeof(TKey) == typeof(int) || typeof(TKey) == typeof(long) || typeof(TKey) == typeof(Guid)) { if (EntityHelper.IsTransient(entity)) { - entity.Id = Database.GenerateNextId(); + entity.Id = Database.GenerateNextId(); } } } - public virtual TEntity Find(TPrimaryKey id) + public virtual TEntity Find(TKey id) { - return GetQueryable().FirstOrDefault(EntityHelper.CreateEqualityExpressionForId(id)); + return GetQueryable().FirstOrDefault(EntityHelper.CreateEqualityExpressionForId(id)); } - public virtual TEntity Get(TPrimaryKey id) + public virtual TEntity Get(TKey id) { var entity = Find(id); @@ -88,17 +88,17 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb return entity; } - public virtual Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + public virtual Task GetAsync(TKey id, CancellationToken cancellationToken = default) { return Task.FromResult(Get(id)); } - public virtual Task FindAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + public virtual Task FindAsync(TKey id, CancellationToken cancellationToken = default) { return Task.FromResult(Find(id)); } - public virtual void Delete(TPrimaryKey id) + public virtual void Delete(TKey id) { var entity = Find(id); if (entity == null) @@ -109,7 +109,7 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb Delete(entity); } - public virtual Task DeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + public virtual Task DeleteAsync(TKey id, CancellationToken cancellationToken = default) { Delete(id); return Task.CompletedTask; diff --git a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDbCoreRepositoryExtensions.cs b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDbCoreRepositoryExtensions.cs index 71192d03ed..4071646c7d 100644 --- a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDbCoreRepositoryExtensions.cs +++ b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDbCoreRepositoryExtensions.cs @@ -7,25 +7,25 @@ namespace Volo.Abp.Domain.Repositories { public static class MemoryDbCoreRepositoryExtensions { - public static IMemoryDatabase GetDatabase(this IRepository repository) - where TEntity : class, IEntity + public static IMemoryDatabase GetDatabase(this IRepository repository) + where TEntity : class, IEntity { return repository.ToMemoryDbRepository().Database; } - public static List GetCollection(this IRepository repository) - where TEntity : class, IEntity + public static List GetCollection(this IRepository repository) + where TEntity : class, IEntity { return repository.ToMemoryDbRepository().Collection; } - public static IMemoryDbRepository ToMemoryDbRepository(this IRepository repository) - where TEntity : class, IEntity + public static IMemoryDbRepository ToMemoryDbRepository(this IRepository repository) + where TEntity : class, IEntity { - var memoryDbRepository = repository as IMemoryDbRepository; + var memoryDbRepository = repository as IMemoryDbRepository; if (memoryDbRepository == null) { - throw new ArgumentException("Given repository does not implement " + typeof(IMemoryDbRepository).AssemblyQualifiedName, nameof(repository)); + throw new ArgumentException("Given repository does not implement " + typeof(IMemoryDbRepository).AssemblyQualifiedName, nameof(repository)); } return memoryDbRepository; diff --git a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs index c20c5dca1e..c8f5eb0265 100644 --- a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs +++ b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs @@ -13,8 +13,8 @@ namespace Volo.Abp.Domain.Repositories.MongoDB string CollectionName { get; } } - public interface IMongoDbRepository : IMongoDbRepository, IQueryableRepository - where TEntity : class, IEntity + public interface IMongoDbRepository : IMongoDbRepository, IQueryableRepository + where TEntity : class, IEntity { } diff --git a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs index 3141da949e..348ed9e957 100644 --- a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs +++ b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs @@ -81,9 +81,9 @@ namespace Volo.Abp.Domain.Repositories.MongoDB } } - public class MongoDbRepository : MongoDbRepository, IMongoDbRepository + public class MongoDbRepository : MongoDbRepository, IMongoDbRepository where TMongoDbContext : AbpMongoDbContext - where TEntity : class, IEntity + where TEntity : class, IEntity { public MongoDbRepository(IMongoDatabaseProvider databaseProvider) : base(databaseProvider) @@ -91,7 +91,7 @@ namespace Volo.Abp.Domain.Repositories.MongoDB } - public virtual TEntity Get(TPrimaryKey id) + public virtual TEntity Get(TKey id) { var entity = Find(id); @@ -103,7 +103,7 @@ namespace Volo.Abp.Domain.Repositories.MongoDB return entity; } - public virtual async Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + public virtual async Task GetAsync(TKey id, CancellationToken cancellationToken = default) { var entity = await FindAsync(id, cancellationToken); @@ -115,22 +115,22 @@ namespace Volo.Abp.Domain.Repositories.MongoDB return entity; } - public virtual void Delete(TPrimaryKey id) + public virtual void Delete(TKey id) { Collection.DeleteOne(CreateEntityFilter(id)); } - public virtual Task DeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + public virtual Task DeleteAsync(TKey id, CancellationToken cancellationToken = default) { return Collection.DeleteOneAsync(CreateEntityFilter(id), cancellationToken); } - public virtual async Task FindAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + public virtual async Task FindAsync(TKey id, CancellationToken cancellationToken = default) { return await Collection.Find(CreateEntityFilter(id)).FirstOrDefaultAsync(cancellationToken); } - public virtual TEntity Find(TPrimaryKey id) + public virtual TEntity Find(TKey id) { return Collection.Find(CreateEntityFilter(id)).FirstOrDefault(); } @@ -140,7 +140,7 @@ namespace Volo.Abp.Domain.Repositories.MongoDB return Builders.Filter.Eq(e => e.Id, entity.Id); } - private static FilterDefinition CreateEntityFilter(TPrimaryKey id) + private static FilterDefinition CreateEntityFilter(TKey id) { return Builders.Filter.Eq(e => e.Id, id); } diff --git a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDbCoreRepositoryExtensions.cs b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDbCoreRepositoryExtensions.cs index b553637002..dba22e8e1b 100644 --- a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDbCoreRepositoryExtensions.cs +++ b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDbCoreRepositoryExtensions.cs @@ -7,31 +7,31 @@ namespace Volo.Abp.Domain.Repositories { public static class MongoDbCoreRepositoryExtensions { - public static IMongoDatabase GetDatabase(this IRepository repository) - where TEntity : class, IEntity + public static IMongoDatabase GetDatabase(this IRepository repository) + where TEntity : class, IEntity { return repository.ToMongoDbRepository().Database; } - public static IMongoCollection GetCollection(this IRepository repository) - where TEntity : class, IEntity + public static IMongoCollection GetCollection(this IRepository repository) + where TEntity : class, IEntity { return repository.ToMongoDbRepository().Collection; } - public static string GetCollectionName(this IRepository repository) - where TEntity : class, IEntity + public static string GetCollectionName(this IRepository repository) + where TEntity : class, IEntity { return repository.ToMongoDbRepository().CollectionName; } - public static IMongoDbRepository ToMongoDbRepository(this IRepository repository) - where TEntity : class, IEntity + public static IMongoDbRepository ToMongoDbRepository(this IRepository repository) + where TEntity : class, IEntity { - var mongoDbRepository = repository as IMongoDbRepository; + var mongoDbRepository = repository as IMongoDbRepository; if (mongoDbRepository == null) { - throw new ArgumentException("Given repository does not implement " + typeof(IMongoDbRepository).AssemblyQualifiedName, nameof(repository)); + throw new ArgumentException("Given repository does not implement " + typeof(IMongoDbRepository).AssemblyQualifiedName, nameof(repository)); } return mongoDbRepository; diff --git a/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs b/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs index 372f3fb6b9..5f082eb52a 100644 --- a/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs +++ b/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs @@ -169,35 +169,35 @@ namespace Volo.Abp.Domain.Repositories } } - public class MyTestDefaultRepository : MyTestDefaultRepository, IRepository - where TEntity : class, IEntity + public class MyTestDefaultRepository : MyTestDefaultRepository, IRepository + where TEntity : class, IEntity { - public TEntity Get(TPrimaryKey id) + public TEntity Get(TKey id) { throw new NotImplementedException(); } - public Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + public Task GetAsync(TKey id, CancellationToken cancellationToken = default) { throw new NotImplementedException(); } - public TEntity Find(TPrimaryKey id) + public TEntity Find(TKey id) { throw new NotImplementedException(); } - public Task FindAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + public Task FindAsync(TKey id, CancellationToken cancellationToken = default) { throw new NotImplementedException(); } - public void Delete(TPrimaryKey id) + public void Delete(TKey id) { throw new NotImplementedException(); } - public Task DeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + public Task DeleteAsync(TKey id, CancellationToken cancellationToken = default) { throw new NotImplementedException(); } @@ -214,8 +214,8 @@ namespace Volo.Abp.Domain.Repositories } - public class MyTestCustomBaseRepository : MyTestDefaultRepository - where TEntity : class, IEntity + public class MyTestCustomBaseRepository : MyTestDefaultRepository + where TEntity : class, IEntity { } diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Phone.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Phone.cs index 45f31c705b..142e97463e 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Phone.cs +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Phone.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; using Volo.Abp.Domain.Entities; namespace Volo.Abp.TestApp.Domain @@ -25,4 +27,74 @@ namespace Volo.Abp.TestApp.Domain Type = type; } } + + public class Order : AggregateRoot + { + public virtual string ReferenceNo { get; protected set; } + + public virtual float TotalItemCount { get; protected set; } + + public virtual DateTime CreationTime { get; protected set; } + + public virtual List OrderLines { get; protected set; } + + protected Order() + { + + } + + public Order(Guid id, string referenceNo) + { + Id = id; + ReferenceNo = referenceNo; + OrderLines = new List(); + } + + public void AddProduct(Guid productId, int count) + { + if (count <= 0) + { + throw new ArgumentException("You can not add zero or negative count of products!", nameof(count)); + } + + var existingLine = OrderLines.FirstOrDefault(ol => ol.ProductId == productId); + + if (existingLine == null) + { + OrderLines.Add(new OrderLine(this.Id, productId, count)); + } + else + { + existingLine.ChangeCount(existingLine.Count + count); + } + + TotalItemCount += count; + } + } + + public class OrderLine : Entity + { + public virtual Guid OrderId { get; protected set; } + + public virtual Guid ProductId { get; protected set; } + + public virtual int Count { get; protected set; } + + protected OrderLine() + { + + } + + public OrderLine(Guid orderId, Guid productId, int count) + { + OrderId = orderId; + ProductId = productId; + Count = count; + } + + internal void ChangeCount(int newCount) + { + Count = newCount; + } + } } \ No newline at end of file From 5f716464597b5c4a50773eb771af1efa7c6641c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 26 Jan 2018 14:35:50 +0300 Subject: [PATCH 10/14] Updated entities document --- docs/Entities.md | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/docs/Entities.md b/docs/Entities.md index 67e3856e7b..1777d9829b 100644 --- a/docs/Entities.md +++ b/docs/Entities.md @@ -50,19 +50,21 @@ public class UserRole : Entity For the example above, the composite key is composed of `UserId` and `RoleId`. For a relational database, it is the composite primary key of the related table. -> Composite primary keys has some restriction with repositories. Since it has not known Id property, you can not use `IRepository` for these entities. However, you can always use `IRepository`. See repository documentation (TODO: link) for more. +Notice that you also need to define keys of the entity in your **object-to-relational mapping** (ORM) configuration. + +> Composite primary keys has a restriction with repositories. Since it has not known Id property, you can not use `IRepository` for these entities. However, you can always use `IRepository`. See repository documentation (TODO: link) for more. ### AggregateRoot Class "*Aggregate is a pattern in Domain-Driven Design. A DDD aggregate is a cluster of domain objects that can be treated as a single unit. An example may be an order and its line-items, these will be separate objects, but it's useful to treat the order (together with its line items) as a single aggregate.*" (see the [full description](http://martinfowler.com/bliki/DDD_Aggregate.html)) -`AggregateRoot` extends `Entity`. So, it also has an `Id` property by default. +`AggregateRoot` class extends the `Entity` class. So, it also has an `Id` property by default. > Notice that ABP creates default repositories only for aggregate roots by default. However, it's possible to include all entities. See repository documentation (TODO: link) for more. -ABP does not force you to use aggregate roots, you can only use the `Entity` class as defined before. However, if you want to implement DDD and want to create aggregate root classes, there are some best practices you can consider: +ABP does not force you to use aggregate roots, you can only use the `Entity` class as defined before. However, if you want to implement DDD and want to create aggregate root classes, there are some best practices you may want to consider: -* An aggregate root is responsible to preserve it's own integrity. This is also true for all entities, but aggregate root has responsibility for it's sub entities too. +* An aggregate root is responsible to preserve it's own integrity. This is also true for all entities, but aggregate root has responsibility for it's sub entities too. So, the aggregate root always be in a valid state. * An aggregate root can be referenced by it's Id. Do not reference it by navigation property. * An aggregate root is treated as a single unit. It's retrieved and updated as a single unit. It's generally considered as a transaction boundary. * Work with sub-entities over the aggregate root, do not modify them independently. @@ -89,8 +91,11 @@ public class Order : AggregateRoot public Order(Guid id, string referenceNo) { + Check.NotNull(referenceNo, nameof(referenceNo)); + Id = id; ReferenceNo = referenceNo; + OrderLines = new List(); } @@ -146,8 +151,19 @@ public class OrderLine : Entity } ```` -In this example; +> If you do not want derive your aggregate root from the base `AggregateRoot` class, you can directly implement `IAggregateRoot` interface. + +`Order` is an **aggregate root** with `Guid` type `Id` property. It has a collection of `OrderLine` entities. `OrderLine` is another entity with a composite primary key (`OrderLine` and ` ProductId`). + +While this example may not implement all best practices of an aggregate root, it follows some good practices: + +* `Order` has a public constructor that takes **minimal requirements** to construct an `Order` instance. So, it's not possible to create an order without an id and reference number. The **protected/private** constructor is only necessary to **deserialize** object while reading from a data source. +* `OrderLine` constructor is internal, so it only allows to be created by the domain layer. It's used inside of `Order.AddProduct` method. +* `Order.AddProduct` implements the business rule to add a product to an order. +* All properties have `protected` setters. This is to prevent entity from arbitrary changes from outside of the entity. For instance, it would be dangerous to set `TotalItemCount` without adding a new product to the order. It's value is maintained by the `AddProduct` method. + +ABP does not force you to apply any DDD rule or pattern. However, it tries to make it possible and easier when you want to apply. The documentation also follows this principle. -* `Order` is an **aggregate root entity** with `Guid` type `Id` property. It has a collection of `OrderLine` entities. `OrderLine` is another entity with a composite primary key (`OrderLine` and ` ProductId`). -* ... +#### Aggregate Roots with Composite Keys +While it's not common (and not suggested) for aggregate roots, it's possible to define composite keys just as defined for entities above. Use non-generic `AggregateRoot` base class in that case. \ No newline at end of file From 260d57a4ecf4e9b914c101424ed956c8ff7599d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 26 Jan 2018 15:01:30 +0300 Subject: [PATCH 11/14] Added repo doc. --- docs/Index.md | 14 +++++++++++++- docs/Repositories.md | 10 ++++++++++ .../Volo/Abp/TestApp/Domain/Person.cs | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 docs/Repositories.md diff --git a/docs/Index.md b/docs/Index.md index 370f40179b..0a8d8ea6c3 100644 --- a/docs/Index.md +++ b/docs/Index.md @@ -12,7 +12,19 @@ * Basics * Plug-In Modules * Best Practices +* Domain Driven Design + * Domain Layer + * [Entities & Aggregate Roots](Entities.md) + * Value Objects + * [Repositories](Repositories.md) + * Domain Services + * Specifications + * Domain Events + * Application Layer + * Application Services + * Data Transfer Objects + * Unit Of Work * Data Access * [Entity Framework Core Integration](Entity-Framework-Core.md) -* Presentation (User Interface) +* Presentation / User Interface * Localization \ No newline at end of file diff --git a/docs/Repositories.md b/docs/Repositories.md new file mode 100644 index 0000000000..1b89fa6443 --- /dev/null +++ b/docs/Repositories.md @@ -0,0 +1,10 @@ +## Repositories + +"*Mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects*" (Martin Fowler). + +Repositories, in practice, are used to perform database operations for domain objects (see [Entities](Entities.md)). Generally, a separated repository is used for each **aggregate root** or entity. + +### Generic Repositories + +ABP can provide a default generic repository for each aggregate root or entity. You can [inject](Dependency-Injection.md) `IRepository` into your service and perform standard CRUD operations. Example usage: + diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs index 553ca30abd..7754f16cda 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs @@ -1,6 +1,8 @@ using System; using System.Collections.ObjectModel; +using Volo.Abp.Application.Services; using Volo.Abp.Domain.Entities; +using Volo.Abp.Domain.Repositories; using Volo.Abp.MultiTenancy; namespace Volo.Abp.TestApp.Domain From 066b07b800354f1a2a40c4eba528e6b4d9d4c551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 26 Jan 2018 15:09:40 +0300 Subject: [PATCH 12/14] Renamed Repository to BasicRepository and QueryableRepository to Repository. --- .../AbpDesk/Tickets/TicketAppService.cs | 4 +- .../AbpDesk/ConsoleDemo/BlogPostLister.cs | 4 +- .../AbpDesk/ConsoleDemo/UserLister.cs | 4 +- .../Blogging/AbpDeskMongoBlogModule.cs | 2 +- .../Areas/Blog/Controllers/PostsController.cs | 4 +- src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll | Bin 13824 -> 13824 bytes .../ServiceCollectionRepositoryExtensions.cs | 8 +- .../Services/AsyncCrudAppService.cs | 8 +- .../Application/Services/CrudAppService.cs | 8 +- .../Services/CrudAppServiceBase.cs | 4 +- .../CommonDbContextRegistrationOptions.cs | 4 +- .../Repositories/BasicRepositoryBase.cs | 90 +++++++++++++ .../Domain/Repositories/IBasicRepository.cs | 114 +++++++++++++++++ .../Repositories/IQueryableRepository.cs | 38 ------ .../Abp/Domain/Repositories/IRepository.cs | 114 +++-------------- .../Repositories/QueryableRepositoryBase.cs | 118 ------------------ .../Abp/Domain/Repositories/RepositoryBase.cs | 72 +++++++---- .../Repositories/RepositoryExtensions.cs | 8 +- .../EfCoreRepositoryExtensions.cs | 6 +- .../EntityFrameworkCore/EfCoreRepository.cs | 2 +- .../EntityFrameworkCore/IEfCoreRepository.cs | 4 +- .../Abp/Identity/IIdentityRoleRepository.cs | 2 +- .../Abp/Identity/IIdentityUserRepository.cs | 2 +- .../ApiResources/IApiResourceRepository.cs | 2 +- .../Clients/IClientRepository.cs | 2 +- .../Grants/IPersistentGrantRepository.cs | 2 +- .../IIdentityResourceRepository.cs | 2 +- .../MemoryDb/IMemoryDbRepository.cs | 4 +- .../MemoryDb/MemoryDbRepository.cs | 2 +- .../MemoryDbCoreRepositoryExtensions.cs | 6 +- .../MongoDB/IMongoDbRepository.cs | 4 +- .../Repositories/MongoDB/MongoDbRepository.cs | 2 +- .../MongoDbCoreRepositoryExtensions.cs | 8 +- .../Abp/MultiTenancy/ITenantRepository.cs | 2 +- .../AspNetCore/Mvc/PersonAppService_Tests.cs | 4 +- .../RepositoryRegistration_Tests.cs | 38 +++--- .../SecondContextTestDataBuilder.cs | 4 +- .../DataFiltering/MultiTenant_Filter_Tests.cs | 4 +- .../DataFiltering/SoftDelete_Filter_Tests.cs | 4 +- .../DbContext_Replace_Tests.cs | 4 +- .../Repositories/Repository_Tests.cs | 12 +- .../EntityFrameworkCore/Transaction_Tests.cs | 8 +- .../PersonAppServiceClientProxy_Tests.cs | 4 +- .../Volo/Abp/Identity/Initialize_Tests.cs | 4 +- .../MemoryDb_SoftDelete_DataFilter_Tests.cs | 4 +- .../DataFilters/MultiTenant_Filter_Tests.cs | 4 +- .../MemoryDb_Basic_Repository_Tests.cs | 4 +- .../TestApp/Application/PeopleAppService.cs | 2 +- .../Volo/Abp/TestApp/TestDataBuilder.cs | 4 +- 49 files changed, 380 insertions(+), 380 deletions(-) create mode 100644 src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs create mode 100644 src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IBasicRepository.cs delete mode 100644 src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IQueryableRepository.cs delete mode 100644 src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs diff --git a/src/AbpDesk/AbpDesk.Application/AbpDesk/Tickets/TicketAppService.cs b/src/AbpDesk/AbpDesk.Application/AbpDesk/Tickets/TicketAppService.cs index dcc897d516..3767772a21 100644 --- a/src/AbpDesk/AbpDesk.Application/AbpDesk/Tickets/TicketAppService.cs +++ b/src/AbpDesk/AbpDesk.Application/AbpDesk/Tickets/TicketAppService.cs @@ -12,11 +12,11 @@ namespace AbpDesk.Tickets { public class TicketAppService : ApplicationService, ITicketAppService { - private readonly IQueryableRepository _ticketRepository; + private readonly IRepository _ticketRepository; private readonly IAsyncQueryableExecuter _asyncQueryableExecuter; public TicketAppService( - IQueryableRepository ticketRepository, + IRepository ticketRepository, IAsyncQueryableExecuter asyncQueryableExecuter) { _ticketRepository = ticketRepository; diff --git a/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/BlogPostLister.cs b/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/BlogPostLister.cs index c0bf2e9556..a7be728c40 100644 --- a/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/BlogPostLister.cs +++ b/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/BlogPostLister.cs @@ -9,11 +9,11 @@ namespace AbpDesk.ConsoleDemo { public class BlogPostLister : ITransientDependency { - private readonly IQueryableRepository _blogPostRepository; + private readonly IRepository _blogPostRepository; private readonly IGuidGenerator _guidGenerator; public BlogPostLister( - IQueryableRepository blogPostRepository, + IRepository blogPostRepository, IGuidGenerator guidGenerator) { _blogPostRepository = blogPostRepository; diff --git a/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/UserLister.cs b/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/UserLister.cs index 46b038c511..2aa8f30245 100644 --- a/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/UserLister.cs +++ b/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/UserLister.cs @@ -11,11 +11,11 @@ namespace AbpDesk.ConsoleDemo public class UserLister : ITransientDependency { private readonly IdentityUserManager _userManager; - private readonly IQueryableRepository _userRepository; + private readonly IRepository _userRepository; public UserLister( IdentityUserManager userManager, - IQueryableRepository userRepository) + IRepository userRepository) { _userManager = userManager; _userRepository = userRepository; diff --git a/src/AbpDesk/AbpDesk.MongoBlog/AbpDesk/Blogging/AbpDeskMongoBlogModule.cs b/src/AbpDesk/AbpDesk.MongoBlog/AbpDesk/Blogging/AbpDeskMongoBlogModule.cs index 90e0b6b1cc..7636bb19b4 100644 --- a/src/AbpDesk/AbpDesk.MongoBlog/AbpDesk/Blogging/AbpDeskMongoBlogModule.cs +++ b/src/AbpDesk/AbpDesk.MongoBlog/AbpDesk/Blogging/AbpDeskMongoBlogModule.cs @@ -47,7 +47,7 @@ namespace AbpDesk.Blogging using (var uow = scope.ServiceProvider.GetRequiredService().Begin()) { - var blogPostRepository = scope.ServiceProvider.GetRequiredService>(); + var blogPostRepository = scope.ServiceProvider.GetRequiredService>(); if (blogPostRepository.Any()) { logger.LogInformation($"No need to seed database since there are already {blogPostRepository.Count()} blog posts!"); diff --git a/src/AbpDesk/AbpDesk.MongoBlog/Areas/Blog/Controllers/PostsController.cs b/src/AbpDesk/AbpDesk.MongoBlog/Areas/Blog/Controllers/PostsController.cs index c38b7a9c2c..dcd44efa0f 100644 --- a/src/AbpDesk/AbpDesk.MongoBlog/Areas/Blog/Controllers/PostsController.cs +++ b/src/AbpDesk/AbpDesk.MongoBlog/Areas/Blog/Controllers/PostsController.cs @@ -10,9 +10,9 @@ namespace Areas.Blog.Controllers [Area("Blog")] public class PostsController : AbpController { - private readonly IQueryableRepository _blogPostRepository; + private readonly IRepository _blogPostRepository; - public PostsController(IQueryableRepository blogPostRepository) + public PostsController(IRepository blogPostRepository) { _blogPostRepository = blogPostRepository; } diff --git a/src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll b/src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll index e75d37d1ba920d4860c758db227497eab4ed1c25..9fbb3846a6069ec71e6f3e9774cf2e38d6f6d9cf 100644 GIT binary patch delta 2142 zcmZXV3v5(H6o&sZckkT0ySMG_0tL#e4=QZ~mGUeB(jX`h9+sy8jnK3r4Mjk}2$(EL zC8)GeZZwjDJd9SvAh3{tfoO%TfPfVgH9Qnl3Izg06N`ZH%Z`XuLkm5k9_G<8K!JBBuctSSde8}P1%;{BBhe<*Jq;kl zM(-zq_aukqMvBA@U$5*0Aal~9m&;yyaiNNs-5xk^ux-jDjOYZoY|9)uW%LOCPWH;I z#o>7}mP?|SY5FC?nvQReorF9;AdzU!wj^e0j?=90Da&Br6?Q5>YAfo1qSHEvV*m*^&ak{Xpho zOmMf%!z|x@q+q^to!L%a=YzeEE)))-3JZAIK4T9jO5<}&yuywU>a=~4c$d#Qku7~t zY!@*faP27=94NE~pqQBoiz#uyips7y?N{?3ov6&fmcU6f15eqi+`jfMCxnW?E=S^R zopUBQa~Q{U?YS~4L)fW*qOedWc!!ya;j)r9_|vZ}n@kmR(aNxL(bL(@C)*v^E!8z& zR^X;ke=eT0%Y(xnDWB0~z5oG3`=&ch<|bB_R)tPU6W^N;0WEEI2H4dWM!JiR+!${n zh;B$nvy&pGE+1&5iF~}}&lH3ml*a5P6it!C{7PGX(!51|*s`AI18~tB8fYJ0W=~{G zX__i@6%IMi3xPFS)#H1+gw@Tsx+Kelfo83$5uka(hjkge468aU*hte#m9|0HSP)Y<$vXtGTB~|w%Ww@jI24oqEJLZNR!97K zh6@L$;=U=eh7xc#?wcW9B;c30Z=1DMB%(3y+hKje>UP{WnGcwR=D2SrZ=VF}t`4CK z9l(7N)KXQtm)!+gsoH9&EzW5b``Ox}@nNKAIa%Smj_R!}ehdg7=y{9>Ol4`wwcIiS zX9c+1Zs|xhZynPzeypM5%Z2M2D3h-1!(L0pmj+|>W0_51B=bk2BQt;;ri*;dL7Kxf zM>E@Df}T&)EY>X3T%fr`vyPbxKdGGgOc%w>9IRlw#1hJKhT~1z;Y>qkwv-{ffkrv= z&|QnIw9%-TApqhn>xOgAduOBKzS}b3gUNHuE6m3w6~b&IRizS*IQ(ru)C99NHT^ zMWe-vNOIyp%4!hb@|`s~il>8Tm?I4}FOiC$Sr?e4-rS@mgY)_AVex2Or2bmAv^COv zzGF4i+w^c0cu5oU8IfE^tbar=ggTi zJ14Wvjm?eQTYO)%Gz`SHO7leiksv>nbq!32+g;A|M(@o()LT5 z^O*sBZ`4p4=2?{##tBU0{4q+%0R9Npki>4}Mfqd7k&sz9Bl?ksE25IJaoFdEvT>{7 zhQ{C-v&ziICMRZ&!2+Yo%*O_F`@@(c+njM&VI{bT8AwQpUPB$=a!}2eu_X&3i_8gl zAb3EQV5tw3g(jyTS-3^^^TA$29!100iq*XAW8)wvD&%uZJjISM4r}`w@iL!v9$U&# zZ`Cl#so_LZ165`P>Y3RHG9}v0gdBq&Tg^{737L<#1Ks|7+;6FJ@3h*SFj@j_j>I;d za}hXm6vuS!B{Cty_&|R}>xDYOPG&Y{$QW<%r>!iz{3_<0IgZaX(K#R|;6UJjRM-5g z0yl;FbFs);5uEm)vWz}|Jp>HxTj=!pUu9)#Rpr$6@xA#F(9&UNfL)m|@?4DO#@LJ? zZbcrhJ6Ynv<|#(5D8*L0KoIs(F0()=+9Ja2)RrGLuTmLXUgUWN&UtqSMnt35JhnWR zs|wwO4ried*rHV@zO(9BT~4WAWP>m;pj8ZMv|RYGJ)f6h)5s{_jvudR)rl|c)xwYX z5Z_^~Vk0+N&FnjqjI`UMqLuu(pyg5fxNtemm6Y?W)5=|VE#B(vr+n|4yF?m#Q@(xXURJ-Sd=K*h(=m|pJ;vLog9_ClbfFd8 z7eOsmrETn~iQXHLp6QH@{_UvVituAV*sbSDw)>T3Fg*M~!b6G-oo0 zW3HapYA)7n&|ImxRJvJF}@0O;kr$&}B$uh`r2&E@iSVanBOGCz@y)i>JA3RE>FJvs}-Ywv3le z*Op9ujS+F&d0lVt4trH(IrjSxQ90iAAEr{FuA0Q@UY=CT zr84fm3_P}#qdd8(4;nDWo)%B~^E`GGJK0Z2pyX$V>+fhBY zWa<4c - var repositoryInterfaceWithoutPk = typeof(IRepository<>).MakeGenericType(entityType); + var repositoryInterfaceWithoutPk = typeof(IBasicRepository<>).MakeGenericType(entityType); if (!repositoryInterfaceWithoutPk.IsAssignableFrom(repositoryImplementationType)) { throw new AbpException($"Given repositoryImplementationType ({repositoryImplementationType}) must implement {repositoryInterfaceWithoutPk}"); @@ -21,7 +21,7 @@ namespace Microsoft.Extensions.DependencyInjection services.TryAddTransient(repositoryInterfaceWithoutPk, repositoryImplementationType); //IQueryableRepository - var queryableRepositoryInterfaceWithPk = typeof(IQueryableRepository<>).MakeGenericType(entityType); + var queryableRepositoryInterfaceWithPk = typeof(IRepository<>).MakeGenericType(entityType); if (repositoryInterfaceWithoutPk.IsAssignableFrom(repositoryImplementationType)) { services.TryAddTransient(queryableRepositoryInterfaceWithPk, repositoryImplementationType); @@ -32,14 +32,14 @@ namespace Microsoft.Extensions.DependencyInjection if (primaryKeyType != null) { //IRepository - var repositoryInterface = typeof(IRepository<,>).MakeGenericType(entityType, primaryKeyType); + var repositoryInterface = typeof(IBasicRepository<,>).MakeGenericType(entityType, primaryKeyType); if (repositoryInterface.GetTypeInfo().IsAssignableFrom(repositoryImplementationType)) { services.TryAddTransient(repositoryInterface, repositoryImplementationType); } //IQueryableRepository - var queryableRepositoryInterface = typeof(IQueryableRepository<,>).MakeGenericType(entityType, primaryKeyType); + var queryableRepositoryInterface = typeof(IRepository<,>).MakeGenericType(entityType, primaryKeyType); if (queryableRepositoryInterface.GetTypeInfo().IsAssignableFrom(repositoryImplementationType)) { services.TryAddTransient(queryableRepositoryInterface, repositoryImplementationType); diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/AsyncCrudAppService.cs b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/AsyncCrudAppService.cs index bbd4a8eaeb..108b73b1ba 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/AsyncCrudAppService.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/AsyncCrudAppService.cs @@ -12,7 +12,7 @@ namespace Volo.Abp.Application.Services where TEntity : class, IEntity where TEntityDto : IEntityDto { - protected AsyncCrudAppService(IQueryableRepository repository) + protected AsyncCrudAppService(IRepository repository) : base(repository) { @@ -24,7 +24,7 @@ namespace Volo.Abp.Application.Services where TEntity : class, IEntity where TEntityDto : IEntityDto { - protected AsyncCrudAppService(IQueryableRepository repository) + protected AsyncCrudAppService(IRepository repository) : base(repository) { @@ -38,7 +38,7 @@ namespace Volo.Abp.Application.Services where TEntityDto : IEntityDto where TCreateInput : IEntityDto { - protected AsyncCrudAppService(IQueryableRepository repository) + protected AsyncCrudAppService(IRepository repository) : base(repository) { @@ -53,7 +53,7 @@ namespace Volo.Abp.Application.Services { public IAsyncQueryableExecuter AsyncQueryableExecuter { get; set; } - protected AsyncCrudAppService(IQueryableRepository repository) + protected AsyncCrudAppService(IRepository repository) :base(repository) { AsyncQueryableExecuter = DefaultAsyncQueryableExecuter.Instance; diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppService.cs b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppService.cs index 367552dba0..68618a553e 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppService.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppService.cs @@ -10,7 +10,7 @@ namespace Volo.Abp.Application.Services where TEntity : class, IEntity where TEntityDto : IEntityDto { - protected CrudAppService(IQueryableRepository repository) + protected CrudAppService(IRepository repository) : base(repository) { @@ -22,7 +22,7 @@ namespace Volo.Abp.Application.Services where TEntity : class, IEntity where TEntityDto : IEntityDto { - protected CrudAppService(IQueryableRepository repository) + protected CrudAppService(IRepository repository) : base(repository) { @@ -35,7 +35,7 @@ namespace Volo.Abp.Application.Services where TEntityDto : IEntityDto where TCreateInput : IEntityDto { - protected CrudAppService(IQueryableRepository repository) + protected CrudAppService(IRepository repository) : base(repository) { @@ -48,7 +48,7 @@ namespace Volo.Abp.Application.Services where TEntity : class, IEntity where TEntityDto : IEntityDto { - protected CrudAppService(IQueryableRepository repository) + protected CrudAppService(IRepository repository) : base(repository) { diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppServiceBase.cs b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppServiceBase.cs index b9ad25a574..0e7e37dcab 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppServiceBase.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppServiceBase.cs @@ -15,7 +15,7 @@ namespace Volo.Abp.Application.Services where TEntity : class, IEntity where TEntityDto : IEntityDto { - protected IQueryableRepository Repository { get; } + protected IRepository Repository { get; } protected virtual string GetPermissionName { get; set; } @@ -27,7 +27,7 @@ namespace Volo.Abp.Application.Services protected virtual string DeletePermissionName { get; set; } - protected CrudAppServiceBase(IQueryableRepository repository) + protected CrudAppServiceBase(IRepository repository) { Repository = repository; } diff --git a/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/CommonDbContextRegistrationOptions.cs b/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/CommonDbContextRegistrationOptions.cs index 917e9bd57a..3ad73cca1c 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/CommonDbContextRegistrationOptions.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/DependencyInjection/CommonDbContextRegistrationOptions.cs @@ -107,9 +107,9 @@ namespace Volo.Abp.DependencyInjection throw new AbpException($"Given entityType is not an entity: {entityType.AssemblyQualifiedName}. It must implement {typeof(IEntity<>).AssemblyQualifiedName}."); } - if (!ReflectionHelper.IsAssignableToGenericType(repositoryType, typeof(IRepository<>))) + if (!ReflectionHelper.IsAssignableToGenericType(repositoryType, typeof(IBasicRepository<>))) { - throw new AbpException($"Given repositoryType is not a repository: {entityType.AssemblyQualifiedName}. It must implement {typeof(IRepository<>).AssemblyQualifiedName}."); + throw new AbpException($"Given repositoryType is not a repository: {entityType.AssemblyQualifiedName}. It must implement {typeof(IBasicRepository<>).AssemblyQualifiedName}."); } CustomRepositories[entityType] = repositoryType; diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs new file mode 100644 index 0000000000..5870aeef06 --- /dev/null +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs @@ -0,0 +1,90 @@ +using System.Threading; +using System.Threading.Tasks; +using Volo.Abp.Domain.Entities; +using Volo.Abp.Threading; + +namespace Volo.Abp.Domain.Repositories +{ + public abstract class BasicRepositoryBase : IBasicRepository + where TEntity : class, IEntity + { + public ICancellationTokenProvider CancellationTokenProvider { get; set; } + + protected BasicRepositoryBase() + { + CancellationTokenProvider = NullCancellationTokenProvider.Instance; + } + + public abstract TEntity Insert(TEntity entity, bool autoSave = false); + + public virtual Task InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) + { + return Task.FromResult(Insert(entity, autoSave)); + } + + public abstract TEntity Update(TEntity entity); + + public virtual Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default) + { + return Task.FromResult(Update(entity)); + } + + public abstract void Delete(TEntity entity); + + public virtual Task DeleteAsync(TEntity entity, CancellationToken cancellationToken = default) + { + Delete(entity); + return Task.CompletedTask; + } + + protected virtual CancellationToken GetCancellationToken(CancellationToken prefferedValue = default) + { + return CancellationTokenProvider.FallbackToProvider(prefferedValue); + } + } + + public abstract class BasicRepositoryBase : BasicRepositoryBase, IBasicRepository + where TEntity : class, IEntity + { + public virtual TEntity Get(TKey id) + { + var entity = Find(id); + + if (entity == null) + { + throw new EntityNotFoundException(typeof(TEntity), id); + } + + return entity; + } + + public virtual Task GetAsync(TKey id, CancellationToken cancellationToken = default) + { + return Task.FromResult(Get(id)); + } + + public abstract TEntity Find(TKey id); + + public virtual Task FindAsync(TKey id, CancellationToken cancellationToken = default) + { + return Task.FromResult(Find(id)); + } + + public virtual void Delete(TKey id) + { + var entity = Find(id); + if (entity == null) + { + return; + } + + Delete(entity); + } + + public virtual Task DeleteAsync(TKey id, CancellationToken cancellationToken = default) + { + Delete(id); + return Task.CompletedTask; + } + } +} diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IBasicRepository.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IBasicRepository.cs new file mode 100644 index 0000000000..91984a1848 --- /dev/null +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IBasicRepository.cs @@ -0,0 +1,114 @@ +using System.Threading; +using System.Threading.Tasks; +using JetBrains.Annotations; +using Volo.Abp.Domain.Entities; + +namespace Volo.Abp.Domain.Repositories +{ + public interface IBasicRepository : IRepository + where TEntity : class, IEntity + { + /// + /// Inserts a new entity. + /// + /// Inserted entity + /// + /// Set true to automatically save changes to database. + /// This can be used to set database generated Id of an entity for some ORMs (like Entity Framework). + /// + [NotNull] + TEntity Insert([NotNull] TEntity entity, bool autoSave = false); + + /// + /// Inserts a new entity. + /// + /// + /// Set true to automatically save changes to database. + /// This can be used to set database generated Id of an entity for some ORMs (like Entity Framework). + /// + /// A to observe while waiting for the task to complete. + /// Inserted entity + [NotNull] + Task InsertAsync([NotNull] TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default); + + /// + /// Updates an existing entity. + /// + /// Entity + [NotNull] + TEntity Update([NotNull] TEntity entity); + + /// + /// Updates an existing entity. + /// + /// A to observe while waiting for the task to complete. + /// Entity + [NotNull] + Task UpdateAsync([NotNull] TEntity entity, CancellationToken cancellationToken = default); + + /// + /// Deletes an entity. + /// + /// Entity to be deleted + void Delete([NotNull] TEntity entity); //TODO: Return true if deleted + + /// + /// Deletes an entity. + /// + /// A to observe while waiting for the task to complete. + /// Entity to be deleted + Task DeleteAsync([NotNull] TEntity entity, CancellationToken cancellationToken = default); //TODO: Return true if deleted + } + + public interface IBasicRepository : IBasicRepository + where TEntity : class, IEntity + { + /// + /// Gets an entity with given primary key. + /// Throws if can not find an entity with given id. + /// + /// Primary key of the entity to get + /// Entity + [NotNull] + TEntity Get(TKey id); + + /// + /// Gets an entity with given primary key. + /// Throws if can not find an entity with given id. + /// + /// Primary key of the entity to get + /// A to observe while waiting for the task to complete. + /// Entity + [NotNull] + Task GetAsync(TKey id, CancellationToken cancellationToken = default); + + /// + /// Gets an entity with given primary key or null if not found. + /// + /// Primary key of the entity to get + /// Entity or null + [CanBeNull] + TEntity Find(TKey id); + + /// + /// Gets an entity with given primary key or null if not found. + /// + /// Primary key of the entity to get + /// A to observe while waiting for the task to complete. + /// Entity or null + Task FindAsync(TKey id, CancellationToken cancellationToken = default); + + /// + /// Deletes an entity by primary key. + /// + /// Primary key of the entity + void Delete(TKey id); //TODO: Return true if deleted + + /// + /// Deletes an entity by primary key. + /// + /// A to observe while waiting for the task to complete. + /// Primary key of the entity + Task DeleteAsync(TKey id, CancellationToken cancellationToken = default); //TODO: Return true if deleted + } +} diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IQueryableRepository.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IQueryableRepository.cs deleted file mode 100644 index 52014849ad..0000000000 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IQueryableRepository.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Linq; -using System.Linq.Expressions; -using System.Threading; -using System.Threading.Tasks; -using JetBrains.Annotations; -using Volo.Abp.Domain.Entities; - -namespace Volo.Abp.Domain.Repositories -{ - public interface IQueryableRepository : IRepository, IQueryable - where TEntity : class, IEntity - { - /// - /// Deletes many entities by function. - /// Notice that: All entities fits to given predicate are retrieved and deleted. - /// This may cause major performance problems if there are too many entities with - /// given predicate. - /// - /// A condition to filter entities - void Delete([NotNull] Expression> predicate); - - /// - /// Deletes many entities by function. - /// Notice that: All entities fits to given predicate are retrieved and deleted. - /// This may cause major performance problems if there are too many entities with - /// given predicate. - /// - /// A to observe while waiting for the task to complete. - /// A condition to filter entities - Task DeleteAsync([NotNull] Expression> predicate, CancellationToken cancellationToken = default); - } - - public interface IQueryableRepository : IQueryableRepository, IRepository - where TEntity : class, IEntity - { - } -} \ No newline at end of file diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs index 94521c7628..e927334b26 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs @@ -1,4 +1,7 @@ -using System.Threading; +using System; +using System.Linq; +using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; using JetBrains.Annotations; using Volo.Abp.DependencyInjection; @@ -14,110 +17,31 @@ namespace Volo.Abp.Domain.Repositories } - public interface IRepository : IRepository + public interface IRepository : IBasicRepository, IQueryable where TEntity : class, IEntity { /// - /// Inserts a new entity. + /// Deletes many entities by function. + /// Notice that: All entities fits to given predicate are retrieved and deleted. + /// This may cause major performance problems if there are too many entities with + /// given predicate. /// - /// Inserted entity - /// - /// Set true to automatically save changes to database. - /// This can be used to set database generated Id of an entity for some ORMs (like Entity Framework). - /// - [NotNull] - TEntity Insert([NotNull] TEntity entity, bool autoSave = false); + /// A condition to filter entities + void Delete([NotNull] Expression> predicate); /// - /// Inserts a new entity. + /// Deletes many entities by function. + /// Notice that: All entities fits to given predicate are retrieved and deleted. + /// This may cause major performance problems if there are too many entities with + /// given predicate. /// - /// - /// Set true to automatically save changes to database. - /// This can be used to set database generated Id of an entity for some ORMs (like Entity Framework). - /// /// A to observe while waiting for the task to complete. - /// Inserted entity - [NotNull] - Task InsertAsync([NotNull] TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default); - - /// - /// Updates an existing entity. - /// - /// Entity - [NotNull] - TEntity Update([NotNull] TEntity entity); - - /// - /// Updates an existing entity. - /// - /// A to observe while waiting for the task to complete. - /// Entity - [NotNull] - Task UpdateAsync([NotNull] TEntity entity, CancellationToken cancellationToken = default); - - /// - /// Deletes an entity. - /// - /// Entity to be deleted - void Delete([NotNull] TEntity entity); //TODO: Return true if deleted - - /// - /// Deletes an entity. - /// - /// A to observe while waiting for the task to complete. - /// Entity to be deleted - Task DeleteAsync([NotNull] TEntity entity, CancellationToken cancellationToken = default); //TODO: Return true if deleted + /// A condition to filter entities + Task DeleteAsync([NotNull] Expression> predicate, CancellationToken cancellationToken = default); } - public interface IRepository : IRepository + public interface IRepository : IRepository, IBasicRepository where TEntity : class, IEntity { - /// - /// Gets an entity with given primary key. - /// Throws if can not find an entity with given id. - /// - /// Primary key of the entity to get - /// Entity - [NotNull] - TEntity Get(TKey id); - - /// - /// Gets an entity with given primary key. - /// Throws if can not find an entity with given id. - /// - /// Primary key of the entity to get - /// A to observe while waiting for the task to complete. - /// Entity - [NotNull] - Task GetAsync(TKey id, CancellationToken cancellationToken = default); - - /// - /// Gets an entity with given primary key or null if not found. - /// - /// Primary key of the entity to get - /// Entity or null - [CanBeNull] - TEntity Find(TKey id); - - /// - /// Gets an entity with given primary key or null if not found. - /// - /// Primary key of the entity to get - /// A to observe while waiting for the task to complete. - /// Entity or null - Task FindAsync(TKey id, CancellationToken cancellationToken = default); - - /// - /// Deletes an entity by primary key. - /// - /// Primary key of the entity - void Delete(TKey id); //TODO: Return true if deleted - - /// - /// Deletes an entity by primary key. - /// - /// A to observe while waiting for the task to complete. - /// Primary key of the entity - Task DeleteAsync(TKey id, CancellationToken cancellationToken = default); //TODO: Return true if deleted } -} +} \ No newline at end of file diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs deleted file mode 100644 index f7000714e0..0000000000 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs +++ /dev/null @@ -1,118 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Threading; -using System.Threading.Tasks; -using Volo.Abp.Data; -using Volo.Abp.Domain.Entities; -using Volo.Abp.MultiTenancy; - -namespace Volo.Abp.Domain.Repositories -{ - public abstract class QueryableRepositoryBase : RepositoryBase, IQueryableRepository - where TEntity : class, IEntity - { - public IDataFilter DataFilter { get; set; } - - public ICurrentTenant CurrentTenant { get; set; } - - public virtual Type ElementType => GetQueryable().ElementType; - - public virtual Expression Expression => GetQueryable().Expression; - - public virtual IQueryProvider Provider => GetQueryable().Provider; - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - public IEnumerator GetEnumerator() - { - return GetQueryable().GetEnumerator(); - } - - protected abstract IQueryable GetQueryable(); - - public virtual void Delete(Expression> predicate) - { - foreach (var entity in GetQueryable().Where(predicate).ToList()) - { - Delete(entity); - } - } - - public virtual Task DeleteAsync(Expression> predicate, CancellationToken cancellationToken = default) - { - Delete(predicate); - return Task.CompletedTask; - } - - //TODO: Is that needed..? - protected virtual IQueryable ApplyDataFilters(IQueryable query) - { - if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity))) - { - query = query.WhereIf(DataFilter.IsEnabled(), e => ((ISoftDelete)e).IsDeleted == false); - } - - if (typeof(IMultiTenant).IsAssignableFrom(typeof(TEntity))) - { - var tenantId = CurrentTenant.Id; - query = query.WhereIf(DataFilter.IsEnabled(), e => ((IMultiTenant)e).TenantId == tenantId); - } - - return query; - } - } - - public abstract class QueryableRepositoryBase : QueryableRepositoryBase, IQueryableRepository - where TEntity : class, IEntity - { - public virtual TEntity Find(TKey id) - { - return GetQueryable().FirstOrDefault(EntityHelper.CreateEqualityExpressionForId(id)); - } - - public virtual TEntity Get(TKey id) - { - var entity = Find(id); - - if (entity == null) - { - throw new EntityNotFoundException(typeof(TEntity), id); - } - - return entity; - } - - public virtual Task GetAsync(TKey id, CancellationToken cancellationToken = default) - { - return Task.FromResult(Get(id)); - } - - public virtual Task FindAsync(TKey id, CancellationToken cancellationToken = default) - { - return Task.FromResult(Find(id)); - } - - public virtual void Delete(TKey id) - { - var entity = Find(id); - if (entity == null) - { - return; - } - - Delete(entity); - } - - public virtual Task DeleteAsync(TKey id, CancellationToken cancellationToken = default) - { - Delete(id); - return Task.CompletedTask; - } - } -} \ No newline at end of file diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs index 953b967c2c..b716142436 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs @@ -1,51 +1,81 @@ -using System.Threading; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; +using Volo.Abp.Data; using Volo.Abp.Domain.Entities; -using Volo.Abp.Threading; +using Volo.Abp.MultiTenancy; namespace Volo.Abp.Domain.Repositories { - public abstract class RepositoryBase : IRepository + public abstract class RepositoryBase : BasicRepositoryBase, IRepository where TEntity : class, IEntity { - public ICancellationTokenProvider CancellationTokenProvider { get; set; } + public IDataFilter DataFilter { get; set; } - protected RepositoryBase() + public ICurrentTenant CurrentTenant { get; set; } + + public virtual Type ElementType => GetQueryable().ElementType; + + public virtual Expression Expression => GetQueryable().Expression; + + public virtual IQueryProvider Provider => GetQueryable().Provider; + + IEnumerator IEnumerable.GetEnumerator() { - CancellationTokenProvider = NullCancellationTokenProvider.Instance; + return GetEnumerator(); } - public abstract TEntity Insert(TEntity entity, bool autoSave = false); - - public virtual Task InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) + public IEnumerator GetEnumerator() { - return Task.FromResult(Insert(entity, autoSave)); + return GetQueryable().GetEnumerator(); } - public abstract TEntity Update(TEntity entity); + protected abstract IQueryable GetQueryable(); - public virtual Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default) + public virtual void Delete(Expression> predicate) { - return Task.FromResult(Update(entity)); + foreach (var entity in GetQueryable().Where(predicate).ToList()) + { + Delete(entity); + } } - public abstract void Delete(TEntity entity); - - public virtual Task DeleteAsync(TEntity entity, CancellationToken cancellationToken = default) + public virtual Task DeleteAsync(Expression> predicate, CancellationToken cancellationToken = default) { - Delete(entity); + Delete(predicate); return Task.CompletedTask; } - protected virtual CancellationToken GetCancellationToken(CancellationToken prefferedValue = default) + //TODO: Is that needed..? + protected virtual IQueryable ApplyDataFilters(IQueryable query) { - return CancellationTokenProvider.FallbackToProvider(prefferedValue); + if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity))) + { + query = query.WhereIf(DataFilter.IsEnabled(), e => ((ISoftDelete)e).IsDeleted == false); + } + + if (typeof(IMultiTenant).IsAssignableFrom(typeof(TEntity))) + { + var tenantId = CurrentTenant.Id; + query = query.WhereIf(DataFilter.IsEnabled(), e => ((IMultiTenant)e).TenantId == tenantId); + } + + return query; } } public abstract class RepositoryBase : RepositoryBase, IRepository where TEntity : class, IEntity { + public virtual TEntity Find(TKey id) + { + return GetQueryable().FirstOrDefault(EntityHelper.CreateEqualityExpressionForId(id)); + } + public virtual TEntity Get(TKey id) { var entity = Find(id); @@ -63,8 +93,6 @@ namespace Volo.Abp.Domain.Repositories return Task.FromResult(Get(id)); } - public abstract TEntity Find(TKey id); - public virtual Task FindAsync(TKey id, CancellationToken cancellationToken = default) { return Task.FromResult(Find(id)); @@ -87,4 +115,4 @@ namespace Volo.Abp.Domain.Repositories return Task.CompletedTask; } } -} +} \ No newline at end of file diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryExtensions.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryExtensions.cs index ccb4cd2c60..029ee5cd3c 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryExtensions.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryExtensions.cs @@ -12,7 +12,7 @@ namespace Volo.Abp.Domain.Repositories public static class RepositoryExtensions { public static async Task EnsureCollectionLoadedAsync( - this IRepository repository, + this IBasicRepository repository, TEntity entity, Expression>> propertyExpression, CancellationToken cancellationToken = default @@ -28,7 +28,7 @@ namespace Volo.Abp.Domain.Repositories } public static void EnsureCollectionLoaded( - this IRepository repository, + this IBasicRepository repository, TEntity entity, Expression>> propertyExpression ) @@ -39,7 +39,7 @@ namespace Volo.Abp.Domain.Repositories } public static async Task EnsurePropertyLoadedAsync( - this IRepository repository, + this IBasicRepository repository, TEntity entity, Expression> propertyExpression, CancellationToken cancellationToken = default @@ -55,7 +55,7 @@ namespace Volo.Abp.Domain.Repositories } public static void EnsurePropertyLoaded( - this IRepository repository, + this IBasicRepository repository, TEntity entity, Expression> propertyExpression ) diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EfCoreRepositoryExtensions.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EfCoreRepositoryExtensions.cs index 33f34a79bf..a76136dc7b 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EfCoreRepositoryExtensions.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EfCoreRepositoryExtensions.cs @@ -7,19 +7,19 @@ namespace Volo.Abp.Domain.Repositories { public static class EfCoreRepositoryExtensions { - public static DbContext GetDbContext(this IRepository repository) + public static DbContext GetDbContext(this IBasicRepository repository) where TEntity : class, IEntity { return repository.ToEfCoreRepository().DbContext; } - public static DbSet GetDbSet(this IRepository repository) + public static DbSet GetDbSet(this IBasicRepository repository) where TEntity : class, IEntity { return repository.ToEfCoreRepository().DbSet; } - public static IEfCoreRepository ToEfCoreRepository(this IRepository repository) + public static IEfCoreRepository ToEfCoreRepository(this IBasicRepository repository) where TEntity : class, IEntity { var efCoreRepository = repository as IEfCoreRepository; diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs index 322096084d..d30bd6115e 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs @@ -10,7 +10,7 @@ using Volo.Abp.EntityFrameworkCore; namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore { - public class EfCoreRepository : QueryableRepositoryBase, IEfCoreRepository + public class EfCoreRepository : RepositoryBase, IEfCoreRepository where TDbContext : IEfCoreDbContext where TEntity : class, IEntity { diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs index b0354df4c9..31a78f744d 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs @@ -3,7 +3,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore { - public interface IEfCoreRepository : IQueryableRepository + public interface IEfCoreRepository : IRepository where TEntity : class, IEntity { DbContext DbContext { get; } @@ -11,7 +11,7 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore DbSet DbSet { get; } } - public interface IEfCoreRepository : IEfCoreRepository, IQueryableRepository + public interface IEfCoreRepository : IEfCoreRepository, IRepository where TEntity : class, IEntity { diff --git a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs index 87cce9658a..b68ac92ccd 100644 --- a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs +++ b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs @@ -6,7 +6,7 @@ using Volo.Abp.Domain.Repositories; namespace Volo.Abp.Identity { - public interface IIdentityRoleRepository : IRepository + public interface IIdentityRoleRepository : IBasicRepository { Task FindByNormalizedNameAsync(string normalizedRoleName, CancellationToken cancellationToken); diff --git a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs index d764d69d48..0f6acf0151 100644 --- a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs +++ b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs @@ -8,7 +8,7 @@ using Volo.Abp.Domain.Repositories; namespace Volo.Abp.Identity { - public interface IIdentityUserRepository : IRepository + public interface IIdentityUserRepository : IBasicRepository { Task FindByNormalizedUserNameAsync([NotNull] string normalizedUserName, CancellationToken cancellationToken = default); diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs index 1bc5d4793c..0050584088 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs @@ -5,7 +5,7 @@ using Volo.Abp.Domain.Repositories; namespace Volo.Abp.IdentityServer.ApiResources { - public interface IApiResourceRepository : IRepository + public interface IApiResourceRepository : IBasicRepository { Task FindByNameAsync(string name, CancellationToken cancellationToken = default); } diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/IClientRepository.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/IClientRepository.cs index d0c54dffd1..df5bc2bd43 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/IClientRepository.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/IClientRepository.cs @@ -5,7 +5,7 @@ using Volo.Abp.Domain.Repositories; namespace Volo.Abp.IdentityServer.Clients { - public interface IClientRepository : IRepository + public interface IClientRepository : IBasicRepository { Task FindByCliendIdIncludingAllAsync([NotNull] string clientId); } diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/IPersistentGrantRepository.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/IPersistentGrantRepository.cs index 53059b4ce9..414484bc51 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/IPersistentGrantRepository.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/IPersistentGrantRepository.cs @@ -5,7 +5,7 @@ using Volo.Abp.Domain.Repositories; namespace Volo.Abp.IdentityServer.Grants { - public interface IPersistentGrantRepository : IRepository + public interface IPersistentGrantRepository : IBasicRepository { Task FindByKeyAsync(string key); diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceRepository.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceRepository.cs index 1312daa1a0..ea207fc9f1 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceRepository.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceRepository.cs @@ -6,7 +6,7 @@ using ApiResource = Volo.Abp.IdentityServer.ApiResources.ApiResource; namespace Volo.Abp.IdentityServer.IdentityResources { - public interface IIdentityResourceRepository : IRepository + public interface IIdentityResourceRepository : IBasicRepository { Task> FindIdentityResourcesByScopeAsync(string[] scopeNames); diff --git a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/IMemoryDbRepository.cs b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/IMemoryDbRepository.cs index 6b89208130..dd241b25a5 100644 --- a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/IMemoryDbRepository.cs +++ b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/IMemoryDbRepository.cs @@ -3,7 +3,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.Domain.Repositories.MemoryDb { - public interface IMemoryDbRepository : IQueryableRepository + public interface IMemoryDbRepository : IRepository where TEntity : class, IEntity { IMemoryDatabase Database { get; } @@ -11,7 +11,7 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb List Collection { get; } } - public interface IMemoryDbRepository : IMemoryDbRepository, IQueryableRepository + public interface IMemoryDbRepository : IMemoryDbRepository, IRepository where TEntity : class, IEntity { diff --git a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs index 72e84d126f..e8fb1fb098 100644 --- a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs +++ b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs @@ -8,7 +8,7 @@ using Volo.Abp.MemoryDb; namespace Volo.Abp.Domain.Repositories.MemoryDb { - public class MemoryDbRepository : QueryableRepositoryBase, IMemoryDbRepository + public class MemoryDbRepository : RepositoryBase, IMemoryDbRepository where TMemoryDbContext : MemoryDbContext where TEntity : class, IEntity { diff --git a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDbCoreRepositoryExtensions.cs b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDbCoreRepositoryExtensions.cs index 4071646c7d..6f940ca146 100644 --- a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDbCoreRepositoryExtensions.cs +++ b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDbCoreRepositoryExtensions.cs @@ -7,19 +7,19 @@ namespace Volo.Abp.Domain.Repositories { public static class MemoryDbCoreRepositoryExtensions { - public static IMemoryDatabase GetDatabase(this IRepository repository) + public static IMemoryDatabase GetDatabase(this IBasicRepository repository) where TEntity : class, IEntity { return repository.ToMemoryDbRepository().Database; } - public static List GetCollection(this IRepository repository) + public static List GetCollection(this IBasicRepository repository) where TEntity : class, IEntity { return repository.ToMemoryDbRepository().Collection; } - public static IMemoryDbRepository ToMemoryDbRepository(this IRepository repository) + public static IMemoryDbRepository ToMemoryDbRepository(this IBasicRepository repository) where TEntity : class, IEntity { var memoryDbRepository = repository as IMemoryDbRepository; diff --git a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs index c8f5eb0265..31a39eb3a2 100644 --- a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs +++ b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs @@ -3,7 +3,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.Domain.Repositories.MongoDB { - public interface IMongoDbRepository : IQueryableRepository + public interface IMongoDbRepository : IRepository where TEntity : class, IEntity { IMongoDatabase Database { get; } @@ -13,7 +13,7 @@ namespace Volo.Abp.Domain.Repositories.MongoDB string CollectionName { get; } } - public interface IMongoDbRepository : IMongoDbRepository, IQueryableRepository + public interface IMongoDbRepository : IMongoDbRepository, IRepository where TEntity : class, IEntity { diff --git a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs index 348ed9e957..717f9a5771 100644 --- a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs +++ b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs @@ -9,7 +9,7 @@ using Volo.Abp.MongoDB; namespace Volo.Abp.Domain.Repositories.MongoDB { - public class MongoDbRepository : QueryableRepositoryBase, IMongoDbRepository + public class MongoDbRepository : RepositoryBase, IMongoDbRepository where TMongoDbContext : AbpMongoDbContext where TEntity : class, IEntity { diff --git a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDbCoreRepositoryExtensions.cs b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDbCoreRepositoryExtensions.cs index dba22e8e1b..02a80cfa3a 100644 --- a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDbCoreRepositoryExtensions.cs +++ b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDbCoreRepositoryExtensions.cs @@ -7,25 +7,25 @@ namespace Volo.Abp.Domain.Repositories { public static class MongoDbCoreRepositoryExtensions { - public static IMongoDatabase GetDatabase(this IRepository repository) + public static IMongoDatabase GetDatabase(this IBasicRepository repository) where TEntity : class, IEntity { return repository.ToMongoDbRepository().Database; } - public static IMongoCollection GetCollection(this IRepository repository) + public static IMongoCollection GetCollection(this IBasicRepository repository) where TEntity : class, IEntity { return repository.ToMongoDbRepository().Collection; } - public static string GetCollectionName(this IRepository repository) + public static string GetCollectionName(this IBasicRepository repository) where TEntity : class, IEntity { return repository.ToMongoDbRepository().CollectionName; } - public static IMongoDbRepository ToMongoDbRepository(this IRepository repository) + public static IMongoDbRepository ToMongoDbRepository(this IBasicRepository repository) where TEntity : class, IEntity { var mongoDbRepository = repository as IMongoDbRepository; diff --git a/src/Volo.Abp.MultiTenancy.Domain/Volo/Abp/MultiTenancy/ITenantRepository.cs b/src/Volo.Abp.MultiTenancy.Domain/Volo/Abp/MultiTenancy/ITenantRepository.cs index 563cf8dc0d..b1c73774d9 100644 --- a/src/Volo.Abp.MultiTenancy.Domain/Volo/Abp/MultiTenancy/ITenantRepository.cs +++ b/src/Volo.Abp.MultiTenancy.Domain/Volo/Abp/MultiTenancy/ITenantRepository.cs @@ -4,7 +4,7 @@ using Volo.Abp.Domain.Repositories; namespace Volo.Abp.MultiTenancy { - public interface ITenantRepository : IRepository + public interface ITenantRepository : IBasicRepository { Task FindByNameIncludeDetailsAsync(string name); diff --git a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs index 7076cdd5e0..031a6d6c89 100644 --- a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs +++ b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs @@ -20,13 +20,13 @@ namespace Volo.Abp.AspNetCore.Mvc public class PersonAppService_Tests : AspNetCoreMvcTestBase { - private readonly IQueryableRepository _personRepository; + private readonly IRepository _personRepository; private readonly IJsonSerializer _jsonSerializer; private readonly IObjectMapper _objectMapper; public PersonAppService_Tests() { - _personRepository = ServiceProvider.GetRequiredService>(); + _personRepository = ServiceProvider.GetRequiredService>(); _jsonSerializer = ServiceProvider.GetRequiredService(); _objectMapper = ServiceProvider.GetRequiredService(); } diff --git a/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs b/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs index 5f082eb52a..9fc5e2cff8 100644 --- a/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs +++ b/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs @@ -27,11 +27,11 @@ namespace Volo.Abp.Domain.Repositories //Assert - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); + services.ShouldContainTransient(typeof(IBasicRepository), typeof(MyTestDefaultRepository)); + services.ShouldContainTransient(typeof(IBasicRepository), typeof(MyTestDefaultRepository)); + services.ShouldContainTransient(typeof(IBasicRepository), typeof(MyTestDefaultRepository)); - services.ShouldNotContainService(typeof(IRepository)); + services.ShouldNotContainService(typeof(IBasicRepository)); } [Fact] @@ -50,11 +50,11 @@ namespace Volo.Abp.Domain.Repositories //Assert - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); + services.ShouldContainTransient(typeof(IBasicRepository), typeof(MyTestDefaultRepository)); + services.ShouldContainTransient(typeof(IBasicRepository), typeof(MyTestDefaultRepository)); + services.ShouldContainTransient(typeof(IBasicRepository), typeof(MyTestDefaultRepository)); + services.ShouldContainTransient(typeof(IBasicRepository), typeof(MyTestDefaultRepository)); + services.ShouldContainTransient(typeof(IBasicRepository), typeof(MyTestDefaultRepository)); } [Fact] @@ -75,10 +75,10 @@ namespace Volo.Abp.Domain.Repositories //Assert - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestAggregateRootWithDefaultPkCustomRepository)); - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestAggregateRootWithDefaultPkCustomRepository)); - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestDefaultRepository)); + services.ShouldContainTransient(typeof(IBasicRepository), typeof(MyTestDefaultRepository)); + services.ShouldContainTransient(typeof(IBasicRepository), typeof(MyTestAggregateRootWithDefaultPkCustomRepository)); + services.ShouldContainTransient(typeof(IBasicRepository), typeof(MyTestAggregateRootWithDefaultPkCustomRepository)); + services.ShouldContainTransient(typeof(IBasicRepository), typeof(MyTestDefaultRepository)); } [Fact] @@ -99,10 +99,10 @@ namespace Volo.Abp.Domain.Repositories //Assert - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestCustomBaseRepository)); - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestCustomBaseRepository)); - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestCustomBaseRepository)); - services.ShouldContainTransient(typeof(IRepository), typeof(MyTestCustomBaseRepository)); + services.ShouldContainTransient(typeof(IBasicRepository), typeof(MyTestCustomBaseRepository)); + services.ShouldContainTransient(typeof(IBasicRepository), typeof(MyTestCustomBaseRepository)); + services.ShouldContainTransient(typeof(IBasicRepository), typeof(MyTestCustomBaseRepository)); + services.ShouldContainTransient(typeof(IBasicRepository), typeof(MyTestCustomBaseRepository)); } public class MyTestRepositoryRegistrar : RepositoryRegistrarBase @@ -150,7 +150,7 @@ namespace Volo.Abp.Domain.Repositories public string MyId { get; set; } } - public class MyTestDefaultRepository : RepositoryBase + public class MyTestDefaultRepository : BasicRepositoryBase where TEntity : class, IEntity { public override TEntity Insert(TEntity entity, bool autoSave = false) @@ -169,7 +169,7 @@ namespace Volo.Abp.Domain.Repositories } } - public class MyTestDefaultRepository : MyTestDefaultRepository, IRepository + public class MyTestDefaultRepository : MyTestDefaultRepository, IBasicRepository where TEntity : class, IEntity { public TEntity Get(TKey id) diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/SecondContextTestDataBuilder.cs b/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/SecondContextTestDataBuilder.cs index 5e7658706c..59ddc2acdf 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/SecondContextTestDataBuilder.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/SecondContextTestDataBuilder.cs @@ -7,10 +7,10 @@ namespace Volo.Abp.EntityFrameworkCore.TestApp.SecondContext { public class SecondContextTestDataBuilder : ITransientDependency { - private readonly IRepository _bookRepository; + private readonly IBasicRepository _bookRepository; private readonly IGuidGenerator _guidGenerator; - public SecondContextTestDataBuilder(IRepository bookRepository, IGuidGenerator guidGenerator) + public SecondContextTestDataBuilder(IBasicRepository bookRepository, IGuidGenerator guidGenerator) { _bookRepository = bookRepository; _guidGenerator = guidGenerator; diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/MultiTenant_Filter_Tests.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/MultiTenant_Filter_Tests.cs index e236362bae..976e26ee40 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/MultiTenant_Filter_Tests.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/MultiTenant_Filter_Tests.cs @@ -17,12 +17,12 @@ namespace Volo.Abp.EntityFrameworkCore.DataFiltering public class MultiTenant_Filter_Tests : EntityFrameworkCoreTestBase //TODO: This class is same of Volo.Abp.MemoryDb.DataFilters.MemoryDb_MultiTenant_Filter_Tests. Can we share source code? { private ICurrentTenant _fakeCurrentTenant; - private readonly IQueryableRepository _personRepository; + private readonly IRepository _personRepository; private readonly IDataFilter _multiTenantFilter; public MultiTenant_Filter_Tests() { - _personRepository = GetRequiredService>(); + _personRepository = GetRequiredService>(); _multiTenantFilter = GetRequiredService>(); } diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/SoftDelete_Filter_Tests.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/SoftDelete_Filter_Tests.cs index f845b2ca5f..c17977e463 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/SoftDelete_Filter_Tests.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/SoftDelete_Filter_Tests.cs @@ -10,12 +10,12 @@ namespace Volo.Abp.EntityFrameworkCore.DataFiltering { public class SoftDelete_Filter_Tests : EntityFrameworkCoreTestBase { - private readonly IQueryableRepository _personRepository; + private readonly IRepository _personRepository; private readonly IDataFilter _dataFilter; public SoftDelete_Filter_Tests() { - _personRepository = GetRequiredService>(); + _personRepository = GetRequiredService>(); _dataFilter = GetRequiredService(); } diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DbContext_Replace_Tests.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DbContext_Replace_Tests.cs index 755ea0b3f7..8ada582fa6 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DbContext_Replace_Tests.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DbContext_Replace_Tests.cs @@ -10,11 +10,11 @@ namespace Volo.Abp.EntityFrameworkCore { public class DbContext_Replace_Tests : EntityFrameworkCoreTestBase { - private readonly IRepository _dummyRepository; + private readonly IBasicRepository _dummyRepository; public DbContext_Replace_Tests() { - _dummyRepository = ServiceProvider.GetRequiredService>(); + _dummyRepository = ServiceProvider.GetRequiredService>(); } [Fact] diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Tests.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Tests.cs index 7a98204652..f0ef9066f2 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Tests.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Tests.cs @@ -12,15 +12,15 @@ namespace Volo.Abp.EntityFrameworkCore.Repositories { public class Repository_Tests : EntityFrameworkCoreTestBase { - private readonly IQueryableRepository _personRepository; - private readonly IQueryableRepository _bookRepository; - private readonly IQueryableRepository _phoneInSecondDbContextRepository; + private readonly IRepository _personRepository; + private readonly IRepository _bookRepository; + private readonly IRepository _phoneInSecondDbContextRepository; public Repository_Tests() { - _personRepository = ServiceProvider.GetRequiredService>(); - _bookRepository = ServiceProvider.GetRequiredService>(); - _phoneInSecondDbContextRepository = ServiceProvider.GetRequiredService>(); + _personRepository = ServiceProvider.GetRequiredService>(); + _bookRepository = ServiceProvider.GetRequiredService>(); + _phoneInSecondDbContextRepository = ServiceProvider.GetRequiredService>(); } [Fact] diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Transaction_Tests.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Transaction_Tests.cs index 58fe4b0a38..d37471ee9b 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Transaction_Tests.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Transaction_Tests.cs @@ -12,14 +12,14 @@ namespace Volo.Abp.EntityFrameworkCore { public class Transaction_Tests : EntityFrameworkCoreTestBase { - private readonly IRepository _personRepository; - private readonly IRepository _bookRepository; + private readonly IBasicRepository _personRepository; + private readonly IBasicRepository _bookRepository; private readonly IUnitOfWorkManager _unitOfWorkManager; public Transaction_Tests() { - _personRepository = ServiceProvider.GetRequiredService>(); - _bookRepository = ServiceProvider.GetRequiredService>(); + _personRepository = ServiceProvider.GetRequiredService>(); + _bookRepository = ServiceProvider.GetRequiredService>(); _unitOfWorkManager = ServiceProvider.GetRequiredService(); } diff --git a/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs b/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs index 858b2e007a..568de29522 100644 --- a/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs +++ b/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs @@ -15,12 +15,12 @@ namespace Volo.Abp.Http.DynamicProxying public class PersonAppServiceClientProxy_Tests : AbpHttpTestBase { private readonly IPeopleAppService _peopleAppService; - private readonly IQueryableRepository _personRepository; + private readonly IRepository _personRepository; public PersonAppServiceClientProxy_Tests() { _peopleAppService = ServiceProvider.GetRequiredService(); - _personRepository = ServiceProvider.GetRequiredService>(); + _personRepository = ServiceProvider.GetRequiredService>(); } [Fact] diff --git a/test/Volo.Abp.Identity.Tests/Volo/Abp/Identity/Initialize_Tests.cs b/test/Volo.Abp.Identity.Tests/Volo/Abp/Identity/Initialize_Tests.cs index b6a970e827..69b50be7f7 100644 --- a/test/Volo.Abp.Identity.Tests/Volo/Abp/Identity/Initialize_Tests.cs +++ b/test/Volo.Abp.Identity.Tests/Volo/Abp/Identity/Initialize_Tests.cs @@ -26,10 +26,10 @@ namespace Volo.Abp.Identity { (ServiceProvider.GetRequiredService() is EfCoreIdentityUserRepository).ShouldBeTrue(); - (ServiceProvider.GetRequiredService>() is EfCoreIdentityUserRepository).ShouldBeTrue(); + (ServiceProvider.GetRequiredService>() is EfCoreIdentityUserRepository).ShouldBeTrue(); //(ServiceProvider.GetRequiredService>() is EfCoreIdentityUserRepository).ShouldBeTrue(); - (ServiceProvider.GetRequiredService>() is EfCoreIdentityUserRepository).ShouldBeTrue(); + (ServiceProvider.GetRequiredService>() is EfCoreIdentityUserRepository).ShouldBeTrue(); //(ServiceProvider.GetRequiredService>() is EfCoreIdentityUserRepository).ShouldBeTrue(); } } diff --git a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MemoryDb_SoftDelete_DataFilter_Tests.cs b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MemoryDb_SoftDelete_DataFilter_Tests.cs index 2bf2b7f612..1d73b94561 100644 --- a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MemoryDb_SoftDelete_DataFilter_Tests.cs +++ b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MemoryDb_SoftDelete_DataFilter_Tests.cs @@ -11,12 +11,12 @@ namespace Volo.Abp.MemoryDb.DataFilters { public class MemoryDb_SoftDelete_DataFilter_Tests : MemoryDbTestBase { - private readonly IQueryableRepository _personRepository; + private readonly IRepository _personRepository; private readonly IDataFilter _dataFilter; public MemoryDb_SoftDelete_DataFilter_Tests() { - _personRepository = ServiceProvider.GetRequiredService>(); + _personRepository = ServiceProvider.GetRequiredService>(); _dataFilter = GetRequiredService(); } diff --git a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MultiTenant_Filter_Tests.cs b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MultiTenant_Filter_Tests.cs index 9df33e4899..d5bd1eff73 100644 --- a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MultiTenant_Filter_Tests.cs +++ b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MultiTenant_Filter_Tests.cs @@ -16,12 +16,12 @@ namespace Volo.Abp.MemoryDb.DataFilters public class MemoryDb_MultiTenant_Filter_Tests : MemoryDbTestBase { private ICurrentTenant _fakeCurrentTenant; - private readonly IQueryableRepository _personRepository; + private readonly IRepository _personRepository; private readonly IDataFilter _multiTenantFilter; public MemoryDb_MultiTenant_Filter_Tests() { - _personRepository = GetRequiredService>(); + _personRepository = GetRequiredService>(); _multiTenantFilter = GetRequiredService>(); } diff --git a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/MemoryDb_Basic_Repository_Tests.cs b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/MemoryDb_Basic_Repository_Tests.cs index 3efb7d775e..f96cbf7107 100644 --- a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/MemoryDb_Basic_Repository_Tests.cs +++ b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/MemoryDb_Basic_Repository_Tests.cs @@ -10,11 +10,11 @@ namespace Volo.Abp.MemoryDb.Repositories { public class MemoryDb_Basic_Repository_Tests : MemoryDbTestBase { - private readonly IQueryableRepository _personRepository; + private readonly IRepository _personRepository; public MemoryDb_Basic_Repository_Tests() { - _personRepository = ServiceProvider.GetRequiredService>(); + _personRepository = ServiceProvider.GetRequiredService>(); } [Fact] diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs index bd21d9cf3f..05c6afb7dc 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs @@ -12,7 +12,7 @@ namespace Volo.Abp.TestApp.Application { public class PeopleAppService : AsyncCrudAppService, IPeopleAppService { - public PeopleAppService(IQueryableRepository repository) + public PeopleAppService(IRepository repository) : base(repository) { diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs index a87691ffe8..edc94b51ff 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs @@ -10,9 +10,9 @@ namespace Volo.Abp.TestApp public static Guid TenantId1 { get; } = new Guid("55687dce-595c-41b4-a024-2a5e991ac8f4"); public static Guid TenantId2 { get; } = new Guid("f522d19f-5a86-4278-98fb-0577319c544a"); - private readonly IRepository _personRepository; + private readonly IBasicRepository _personRepository; - public TestDataBuilder(IRepository personRepository) + public TestDataBuilder(IBasicRepository personRepository) { _personRepository = personRepository; } From 908b2fe3edb304f832df95e1e19f6af3799510a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 26 Jan 2018 16:07:45 +0300 Subject: [PATCH 13/14] Added repository doc. --- docs/Data-Transfer-Objects.md | 3 + docs/Object-To-Object-Mapping.md | 3 + docs/Repositories.md | 109 ++++++++++++++++++++++++++++++- 3 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 docs/Data-Transfer-Objects.md create mode 100644 docs/Object-To-Object-Mapping.md diff --git a/docs/Data-Transfer-Objects.md b/docs/Data-Transfer-Objects.md new file mode 100644 index 0000000000..b0d80246f7 --- /dev/null +++ b/docs/Data-Transfer-Objects.md @@ -0,0 +1,3 @@ +## Data Transfer Objects + +TODO \ No newline at end of file diff --git a/docs/Object-To-Object-Mapping.md b/docs/Object-To-Object-Mapping.md new file mode 100644 index 0000000000..b0d80246f7 --- /dev/null +++ b/docs/Object-To-Object-Mapping.md @@ -0,0 +1,3 @@ +## Data Transfer Objects + +TODO \ No newline at end of file diff --git a/docs/Repositories.md b/docs/Repositories.md index 1b89fa6443..969b0c70f6 100644 --- a/docs/Repositories.md +++ b/docs/Repositories.md @@ -6,5 +6,112 @@ Repositories, in practice, are used to perform database operations for domain ob ### Generic Repositories -ABP can provide a default generic repository for each aggregate root or entity. You can [inject](Dependency-Injection.md) `IRepository` into your service and perform standard CRUD operations. Example usage: +ABP can provide a **default generic repository** for each aggregate root or entity. You can [inject](Dependency-Injection.md) `IRepository` into your service and perform standard **CRUD** operations. Example usage: + +````C# +public class PersonAppService : ApplicationService +{ + private readonly IRepository _personRepository; + + public PersonAppService(IRepository personRepository) + { + _personRepository = personRepository; + } + + public async Task Create(CreatePersonDto input) + { + var person = new Person { Name = input.Name, Age = input.Age }; + + await _personRepository.InsertAsync(person); + } + + public List GetList(string nameFilter) + { + var people = _personRepository + .Where(p => p.Name.Contains(nameFilter)) + .ToList(); + + return people + .Select(p => new PersonDto {Id = p.Id, Name = p.Name, Age = p.Age}) + .ToList(); + } +} +```` + +In this example; + +* `PersonAppService` simply injects `IRepository` in it's constructor. +* `Create` method uses `InsertAsync` to save a newly created entity. +* `GetList` method uses the standard LINQ `Where` and `ToList` methods to filter and get a list of people from the data source. + +> The example above uses hand-made mapping between [entities](Entities.md) and [DTO](Data-Transfer-Objects.md)s. See [object to object mapping document](Object-To-Object-Mapping.md) for an automatic way of mapping. + +Generic Repositories provides some standard CRUD features out of the box: + +* Providers `Insert` method to save a new entity. +* Providers `Update` and `Delete` methods to update or delete an entity by entity object or it's id. +* Provides `Delete` method to delete multiple entities by a filter. +* Implements `IQueryable`, so you can use LINQ and extension methods like `FirstOrDefault`, `Where`, `OrderBy`, `ToList` and so on... +* Have **sync** and **async** versions for all methods. + +#### Generic Repository without a Primary Key + +If your entity does not has an Id primary key (it may have a composite primary key for instance) then you can not use the `IRepository` defined above. In that case, you can inject and use `IRepository` for your entity. + +> `IRepository` has a few missing methods those normally works with the `Id` property of an entity. Because of the entity has no `Id` property in that case, these methods are not available. One example is the `Get` method that gets an id and returns the entity with given id. However, you can still use `IQueryable` features to query entities by standard LINQ methods. + +### Basic Repositories + +Standard `IRepository` interface extends standard `IQueryable` and you can freely query using standard LINQ methods. However, some ORM providers or database systems may not support standard `IQueryable` interface. + +ABP provides `IBasicRepository` and `IBasicRepository` interfaces to support such scenarios. You can extend these interfaces (and optionally derive from `BasicRepositoryBase`) to create custom repositories for your entities. + +Depending to `IBasicRepository` but not depending to `IRepository` has an advantage to make possible to work with all data sources even if they don't support `IQueryable`. But major vendors, like Entity Framework, NHibernate or MongoDb already support `IQueryable`. + +So, working with `IRepository` is the **suggested** way for typical applications. But reusable module developers may consider `IBasicRepository` to support wide range of data sources. + +### Custom Repositories + +Default generic repositories will be sufficient for most cases. However, you may need to create a custom repository class for your entity. + +#### Custom Repository Example + +ABP does not force you to implement any interface or inherit from any base class for a repository. It can be just a simple POCO class. However, it's suggested to inherit existing repository interface and classes to make your work easier and get the standard methods out of the box. + +##### Custom Repository Interface + +First, define an interface in your domain layer: + +```c# +public interface IPersonRepository : IRepository +{ + Task FindByNameAsync(string name); +} +``` + +This interface extends `IRepository` to take advantage of pre-built repository functionality. + +##### Custom Repository Implementation + +A custom repository tightly depends on the data access tool you are using. In this example, we will use Entity Framework Core: + +````C# +public class PersonRepository : EfCoreRepository, IPersonRepository +{ + public PersonRepository(IDbContextProvider dbContextProvider) + : base(dbContextProvider) + { + + } + + public async Task FindByNameAsync(string name) + { + return await DbContext.Set() + .Where(p => p.Name == name) + .FirstOrDefaultAsync(); + } +} +```` + +You can directly access to the data access provider (`DbContext` in this case) to perform operations. See [entity framework integration document](Entity-Framework-Core.md) for more about custom repositories based on EF Core. From 2bd084a7f8a3f60f417e7c5d2f695341a4e8da21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 26 Jan 2018 16:11:44 +0300 Subject: [PATCH 14/14] Added todo --- .../Volo/Abp/Application/Services/CrudAppServiceBase.cs | 1 + src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppServiceBase.cs b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppServiceBase.cs index 0e7e37dcab..f3441775a0 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppServiceBase.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppServiceBase.cs @@ -4,6 +4,7 @@ using System.Linq.Dynamic.Core; using Volo.Abp.Application.Dtos; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories; +using Volo.Abp.ObjectMapping; namespace Volo.Abp.Application.Services { diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs index 4cc25837d1..2f19d591f6 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs @@ -18,6 +18,6 @@ /// /// Unique identifier for this entity. /// - TKey Id { get; set; } + TKey Id { get; set; } //TODO: Consider to remove setter and make it protected in Entity class } }