Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
netcoreplus
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
tsai
netcoreplus
Commits
b4171fc1
Commit
b4171fc1
authored
Jun 11, 2019
by
阿星Plus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "TODO MongoDbRepositoryBase"
This reverts commit
e95902dc
.
parent
e95902dc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
21 deletions
+19
-21
IMongoDatabaseProvider.cs
src/Plus.MongoDB/IMongoDatabaseProvider.cs
+7
-4
PlusMongoDbModule.cs
src/Plus.MongoDB/PlusMongoDbModule.cs
+0
-2
MongoDbRepositoryBase.cs
src/Plus.MongoDB/Repositories/MongoDbRepositoryBase.cs
+12
-15
No files found.
src/Plus.MongoDB/IMongoDatabaseProvider.cs
View file @
b4171fc1
...
...
@@ -2,11 +2,14 @@
namespace
Plus.MongoDb
{
/// <summary>
/// Defines interface to obtain a <see cref="MongoDatabase"/> object.
/// </summary>
public
interface
IMongoDatabaseProvider
{
IMongoClient
Client
{
get
;
}
I
MongoDatabase
Database
{
get
;
}
/// <summary>
/// Gets the <see cref="MongoDatabase"/>.
/// </summary>
MongoDatabase
Database
{
get
;
}
}
}
\ No newline at end of file
src/Plus.MongoDB/PlusMongoDbModule.cs
View file @
b4171fc1
using
Plus.Modules
;
using
Plus.MongoDb.Configuration
;
using
Plus.MongoDb.Uow
;
using
System.Reflection
;
namespace
Plus.MongoDb
...
...
@@ -18,7 +17,6 @@ namespace Plus.MongoDb
public
override
void
Initialize
()
{
IocManager
.
Register
<
IMongoDatabaseProvider
,
UnitOfWorkMongoDatabaseProvider
>
();
IocManager
.
RegisterAssembly
(
Assembly
.
GetExecutingAssembly
());
}
}
...
...
src/Plus.MongoDB/Repositories/MongoDbRepositoryBase.cs
View file @
b4171fc1
using
MongoDB.Driver
;
using
MongoDB.Driver.Linq
;
using
Plus.Dependency
;
using
Plus.Domain.Entities
;
using
Plus.Domain.Repositories
;
using
System.Linq
;
...
...
@@ -11,7 +10,8 @@ namespace Plus.MongoDb.Repositories
/// MongoDB Repository
/// </summary>
/// <typeparam name="TEntity"></typeparam>
public
abstract
class
MongoDbRepositoryBase
<
TEntity
>
:
MongoDbRepositoryBase
<
TEntity
,
int
>,
IRepository
<
TEntity
>,
IRepository
<
TEntity
,
int
>,
IRepository
,
ITransientDependency
where
TEntity
:
class
,
IEntity
<
int
>
public
class
MongoDbRepositoryBase
<
TEntity
>
:
MongoDbRepositoryBase
<
TEntity
,
int
>,
IRepository
<
TEntity
>
where
TEntity
:
class
,
IEntity
<
int
>
{
public
MongoDbRepositoryBase
(
IMongoDatabaseProvider
databaseProvider
)
:
base
(
databaseProvider
)
...
...
@@ -24,26 +24,23 @@ namespace Plus.MongoDb.Repositories
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TPrimaryKey"></typeparam>
public
abstract
class
MongoDbRepositoryBase
<
TEntity
,
TPrimaryKey
>
:
PlusRepositoryBase
<
TEntity
,
TPrimaryKey
>
where
TEntity
:
class
,
IEntity
<
TPrimaryKey
>
public
class
MongoDbRepositoryBase
<
TEntity
,
TPrimaryKey
>
:
PlusRepositoryBase
<
TEntity
,
TPrimaryKey
>
where
TEntity
:
class
,
IEntity
<
TPrimaryKey
>
{
private
readonly
IMongoDatabaseProvider
_databaseProvider
;
public
virtual
IMongoDatabase
Database
=>
_databaseProvider
.
Database
;
public
virtual
MongoDatabase
Database
{
get
{
return
_databaseProvider
.
Database
;
}
}
public
virtual
I
MongoCollection
<
TEntity
>
Collection
public
virtual
MongoCollection
<
TEntity
>
Collection
{
get
{
string
name
=
CollectionName
;
if
(
CollectionName
.
IsNullOrEmpty
())
{
name
=
typeof
(
TEntity
).
Name
;
}
return
_databaseProvider
.
Database
.
GetCollection
<
TEntity
>(
name
,
null
);
return
_databaseProvider
.
Database
.
GetCollection
<
TEntity
>(
typeof
(
TEntity
).
Name
);
}
}
p
ublic
abstract
string
CollectionName
{
get
;
}
p
rivate
readonly
IMongoDatabaseProvider
_databaseProvider
;
public
MongoDbRepositoryBase
(
IMongoDatabaseProvider
databaseProvider
)
{
...
...
@@ -58,7 +55,7 @@ namespace Plus.MongoDb.Repositories
public
override
TEntity
Get
(
TPrimaryKey
id
)
{
var
query
=
MongoDB
.
Driver
.
Builders
.
Query
<
TEntity
>.
EQ
(
e
=>
e
.
Id
,
id
);
var
entity
=
Collection
.
Find
(
query
);
var
entity
=
Collection
.
Find
One
(
query
);
if
(
entity
.
IsNull
())
{
throw
new
EntityNotFoundException
(
"There is no such an entity with given primary key. Entity type: "
+
typeof
(
TEntity
).
FullName
+
", primary key: "
+
id
);
...
...
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