Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
ProjectsStatusManagement
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hasan.bahjat
ProjectsStatusManagement
Commits
be66bb06
Commit
be66bb06
authored
Jul 12, 2024
by
hasan khaddour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initiate Shared kernel Structure , Add Abstract Base Classes.
parent
84d14974
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
276 additions
and
5 deletions
+276
-5
IAggregateRoot.cs
PSManagement.SharedKernel/Aggregate/IAggregateRoot.cs
+10
-0
BaseDomainEvent.cs
PSManagement.SharedKernel/DomainEvents/BaseDomainEvent.cs
+10
-0
DomainException.cs
PSManagement.SharedKernel/DomainException/DomainException.cs
+12
-0
BaseEntity.cs
PSManagement.SharedKernel/Entities/BaseEntity.cs
+64
-0
ISpecification.cs
PSManagement.SharedKernel/Interfaces/ISpecification.cs
+20
-0
IUnitOfWork.cs
PSManagement.SharedKernel/Interfaces/IUnitOfWork.cs
+12
-0
PSManagement.SharedKernel.csproj
PSManagement.SharedKernel/PSManagement.SharedKernel.csproj
+2
-5
IReadRepository.cs
PSManagement.SharedKernel/Repositories/IReadRepository.cs
+15
-0
IRepository.cs
PSManagement.SharedKernel/Repositories/IRepository.cs
+17
-0
BaseSpecification.cs
PSManagement.SharedKernel/Specification/BaseSpecification.cs
+50
-0
ValueObject.cs
PSManagement.SharedKernel/ValueObjects/ValueObject.cs
+64
-0
No files found.
PSManagement.SharedKernel/Aggregate/IAggregateRoot.cs
0 → 100644
View file @
be66bb06
using
PSManagement.SharedKernel.Entities
;
namespace
PSManagement.SharedKernel.Aggregate
{
// Apply this marker interface only to aggregate root entities
// Repositories will only work with aggregate roots, not their children
public
class
IAggregateRoot
:
BaseEntity
{
}
}
PSManagement.SharedKernel/DomainEvents/BaseDomainEvent.cs
0 → 100644
View file @
be66bb06
using
MediatR
;
using
System
;
namespace
PSManagement.SharedKernel.Events
{
public
abstract
class
BaseDomainEvent
:
INotification
{
public
DateTime
DateOccurred
{
get
;
protected
set
;
}
=
DateTime
.
UtcNow
;
}
}
PSManagement.SharedKernel/DomainException/DomainException.cs
0 → 100644
View file @
be66bb06
using
System
;
namespace
PSManagement.SharedKernel.DomainException
{
public
class
DomainException
:
Exception
{
public
DomainException
(
string
message
)
:
base
(
message
)
{
}
}
}
PSManagement.SharedKernel/Entities/BaseEntity.cs
0 → 100644
View file @
be66bb06
using
PSManagement.SharedKernel.Events
;
using
System.Collections.Generic
;
namespace
PSManagement.SharedKernel.Entities
{
public
class
BaseEntity
{
public
int
Id
{
get
;
set
;
}
public
List
<
BaseDomainEvent
>
Events
=
new
List
<
BaseDomainEvent
>();
public
static
bool
operator
==(
BaseEntity
first
,
BaseEntity
second
)
{
if
(
first
is
null
&&
second
is
null
)
{
return
true
;
}
if
(
first
is
null
||
second
is
null
)
{
return
false
;
}
return
first
.
Equals
(
second
);
}
public
static
bool
operator
!=(
BaseEntity
first
,
BaseEntity
second
)
{
return
!(
first
==
second
);
}
public
bool
Equals
(
BaseEntity
other
)
{
if
(
other
is
null
||
other
.
GetType
()
!=
GetType
())
{
return
false
;
}
return
other
.
Id
==
Id
;
}
public
override
bool
Equals
(
object
obj
)
{
// Check if the two have same type.
if
(
obj
is
null
||
obj
.
GetType
()
!=
GetType
())
{
return
false
;
}
// Check If the obj if of type Entity.
if
(
obj
is
not
BaseEntity
entity
)
{
return
false
;
}
return
entity
.
Id
==
Id
;
}
public
override
int
GetHashCode
()
{
return
Id
.
GetHashCode
();
}
}
}
PSManagement.SharedKernel/Interfaces/ISpecification.cs
0 → 100644
View file @
be66bb06
using
System
;
using
System.Collections.Generic
;
using
System.Linq.Expressions
;
namespace
PSManagement.SharedKernel.Interfaces
{
public
interface
ISpecification
<
T
>
{
Expression
<
Func
<
T
,
bool
>>
Criteria
{
get
;
}
List
<
Expression
<
Func
<
T
,
object
>>>
Includes
{
get
;
}
List
<
string
>
IncludeStrings
{
get
;
}
Expression
<
Func
<
T
,
object
>>
OrderBy
{
get
;
}
Expression
<
Func
<
T
,
object
>>
OrderByDescending
{
get
;
}
int
Take
{
get
;
}
int
Skip
{
get
;
}
bool
isPagingEnabled
{
get
;
}
}
}
PSManagement.SharedKernel/Interfaces/IUnitOfWork.cs
0 → 100644
View file @
be66bb06
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
PSManagement.SharedKernel.Interfaces
{
public
interface
IUnitOfWork
{
}
}
PSManagement.SharedKernel/PSManagement.SharedKernel.csproj
View file @
be66bb06
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
<Folder Include="Events\" />
<PackageReference Include="MediatR" Version="5.1.0" />
<Folder Include="Abstraction\" />
<Folder Include="Interfaces\" />
<Folder Include="Exception\" />
</ItemGroup>
</ItemGroup>
</Project>
</Project>
PSManagement.SharedKernel/Repositories/IReadRepository.cs
0 → 100644
View file @
be66bb06
using
PSManagement.SharedKernel.Entities
;
using
PSManagement.SharedKernel.Interfaces
;
using
System.Collections.Generic
;
using
System.Threading.Tasks
;
namespace
PSManagement.SharedKernel.Repositories
{
public
interface
IReadRepository
<
T
>
where
T
:
BaseEntity
{
Task
<
T
>
GetByIdAsync
(
int
id
);
Task
<
List
<
T
>>
ListAsync
();
Task
<
List
<
T
>>
ListAsync
(
ISpecification
<
T
>
spec
);
}
}
PSManagement.SharedKernel/Repositories/IRepository.cs
0 → 100644
View file @
be66bb06
using
PSManagement.SharedKernel.Entities
;
using
PSManagement.SharedKernel.Interfaces
;
using
System.Collections.Generic
;
using
System.Threading.Tasks
;
namespace
PSManagement.SharedKernel.Repositories
{
public
interface
IRepository
<
T
>
where
T
:
BaseEntity
{
Task
<
T
>
GetByIdAsync
(
int
id
);
Task
<
List
<
T
>>
ListAsync
();
Task
<
List
<
T
>>
ListAsync
(
ISpecification
<
T
>
spec
);
Task
<
T
>
AddAsync
(
T
entity
);
Task
UpdateAsync
(
T
entity
);
Task
DeleteAsync
(
T
entity
);
}
}
PSManagement.SharedKernel/Specification/BaseSpecification.cs
0 → 100644
View file @
be66bb06
using
PSManagement.SharedKernel.Interfaces
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq.Expressions
;
// Specification Pattern from : https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/microservice-ddd-cqrs-patterns/infrastructure-persistence-layer-implemenation-entity-framework-core
namespace
PSManagement.SharedKernel.Specification
{
public
class
BaseSpecification
<
T
>
:
ISpecification
<
T
>
{
protected
BaseSpecification
(
Expression
<
Func
<
T
,
bool
>>
criteria
)
{
Criteria
=
criteria
;
}
public
Expression
<
Func
<
T
,
bool
>>
Criteria
{
get
;
}
public
List
<
Expression
<
Func
<
T
,
object
>>>
Includes
{
get
;
}
=
new
List
<
Expression
<
Func
<
T
,
object
>>>();
public
List
<
string
>
IncludeStrings
{
get
;
}
=
new
List
<
string
>();
public
Expression
<
Func
<
T
,
object
>>
OrderBy
{
get
;
private
set
;
}
public
Expression
<
Func
<
T
,
object
>>
OrderByDescending
{
get
;
private
set
;
}
public
int
Take
{
get
;
private
set
;
}
public
int
Skip
{
get
;
private
set
;
}
public
bool
isPagingEnabled
{
get
;
private
set
;
}
=
false
;
protected
virtual
void
AddInclude
(
Expression
<
Func
<
T
,
object
>>
includeExpression
)
{
Includes
.
Add
(
includeExpression
);
}
protected
virtual
void
AddInclude
(
string
includeString
)
{
IncludeStrings
.
Add
(
includeString
);
}
protected
virtual
void
ApplyPaging
(
int
skip
,
int
take
)
{
Skip
=
skip
;
Take
=
take
;
isPagingEnabled
=
true
;
}
protected
virtual
void
ApplyOrderBy
(
Expression
<
Func
<
T
,
object
>>
orderByExpression
)
{
OrderBy
=
orderByExpression
;
}
protected
virtual
void
ApplyOrderByDescending
(
Expression
<
Func
<
T
,
object
>>
orderByDescendingExpression
)
{
OrderByDescending
=
orderByDescendingExpression
;
}
}
}
PSManagement.SharedKernel/ValueObjects/ValueObject.cs
0 → 100644
View file @
be66bb06
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
namespace
PSManagement.SharedKernel.ValueObjects
{
public
abstract
class
ValueObject
:
IEquatable
<
ValueObject
>
{
public
static
bool
operator
==(
ValueObject
one
,
ValueObject
two
)
{
return
EqualOperator
(
one
,
two
);
}
public
static
bool
operator
!=(
ValueObject
one
,
ValueObject
two
)
{
return
!
EqualOperator
(
one
,
two
);
}
public
bool
Equals
(
ValueObject
other
)
{
return
other
is
not
null
&&
ValuesAreEqual
(
other
);
}
public
override
bool
Equals
(
object
obj
)
{
if
(
obj
is
null
||
obj
.
GetType
()
!=
GetType
())
{
return
false
;
}
return
obj
is
ValueObject
other
&&
ValuesAreEqual
(
other
);
}
public
override
int
GetHashCode
()
{
return
GetEqualityComponents
()
.
Select
(
x
=>
x
!=
null
?
x
.
GetHashCode
()
:
0
)
.
Aggregate
((
x
,
y
)
=>
x
^
y
);
}
protected
static
bool
EqualOperator
(
ValueObject
left
,
ValueObject
right
)
{
if
(
left
is
null
&&
right
is
null
)
{
return
true
;
}
if
(
left
is
null
||
right
is
null
)
{
return
false
;
}
return
ReferenceEquals
(
left
,
right
)
||
left
.
Equals
(
right
);
}
protected
abstract
IEnumerable
<
object
>
GetEqualityComponents
();
private
bool
ValuesAreEqual
(
ValueObject
other
)
{
return
other
is
not
null
&&
GetEqualityComponents
().
SequenceEqual
(
other
.
GetEqualityComponents
());
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment