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
e95902dc
Commit
e95902dc
authored
Jun 09, 2019
by
阿星Plus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TODO MongoDbRepositoryBase
parent
8317b59a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
19 deletions
+21
-19
IMongoDatabaseProvider.cs
src/Plus.MongoDB/IMongoDatabaseProvider.cs
+4
-7
PlusMongoDbModule.cs
src/Plus.MongoDB/PlusMongoDbModule.cs
+2
-0
MongoDbRepositoryBase.cs
src/Plus.MongoDB/Repositories/MongoDbRepositoryBase.cs
+15
-12
No files found.
src/Plus.MongoDB/IMongoDatabaseProvider.cs
View file @
e95902dc
...
...
@@ -2,14 +2,11 @@
namespace
Plus.MongoDb
{
/// <summary>
/// Defines interface to obtain a <see cref="MongoDatabase"/> object.
/// </summary>
public
interface
IMongoDatabaseProvider
{
/// <summary>
/// Gets the <see cref="MongoDatabase"/>.
/// </summary>
MongoDatabase
Database
{
get
;
}
IMongoClient
Client
{
get
;
}
I
MongoDatabase
Database
{
get
;
}
}
}
\ No newline at end of file
src/Plus.MongoDB/PlusMongoDbModule.cs
View file @
e95902dc
using
Plus.Modules
;
using
Plus.MongoDb.Configuration
;
using
Plus.MongoDb.Uow
;
using
System.Reflection
;
namespace
Plus.MongoDb
...
...
@@ -17,6 +18,7 @@ namespace Plus.MongoDb
public
override
void
Initialize
()
{
IocManager
.
Register
<
IMongoDatabaseProvider
,
UnitOfWorkMongoDatabaseProvider
>
();
IocManager
.
RegisterAssembly
(
Assembly
.
GetExecutingAssembly
());
}
}
...
...
src/Plus.MongoDB/Repositories/MongoDbRepositoryBase.cs
View file @
e95902dc
using
MongoDB.Driver
;
using
MongoDB.Driver.Linq
;
using
Plus.Dependency
;
using
Plus.Domain.Entities
;
using
Plus.Domain.Repositories
;
using
System.Linq
;
...
...
@@ -10,8 +11,7 @@ namespace Plus.MongoDb.Repositories
/// MongoDB Repository
/// </summary>
/// <typeparam name="TEntity"></typeparam>
public
class
MongoDbRepositoryBase
<
TEntity
>
:
MongoDbRepositoryBase
<
TEntity
,
int
>,
IRepository
<
TEntity
>
where
TEntity
:
class
,
IEntity
<
int
>
public
abstract
class
MongoDbRepositoryBase
<
TEntity
>
:
MongoDbRepositoryBase
<
TEntity
,
int
>,
IRepository
<
TEntity
>,
IRepository
<
TEntity
,
int
>,
IRepository
,
ITransientDependency
where
TEntity
:
class
,
IEntity
<
int
>
{
public
MongoDbRepositoryBase
(
IMongoDatabaseProvider
databaseProvider
)
:
base
(
databaseProvider
)
...
...
@@ -24,23 +24,26 @@ namespace Plus.MongoDb.Repositories
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TPrimaryKey"></typeparam>
public
class
MongoDbRepositoryBase
<
TEntity
,
TPrimaryKey
>
:
PlusRepositoryBase
<
TEntity
,
TPrimaryKey
>
where
TEntity
:
class
,
IEntity
<
TPrimaryKey
>
public
abstract
class
MongoDbRepositoryBase
<
TEntity
,
TPrimaryKey
>
:
PlusRepositoryBase
<
TEntity
,
TPrimaryKey
>
where
TEntity
:
class
,
IEntity
<
TPrimaryKey
>
{
public
virtual
MongoDatabase
Database
{
get
{
return
_databaseProvider
.
Database
;
}
}
private
readonly
IMongoDatabaseProvider
_databaseProvider
;
public
virtual
MongoCollection
<
TEntity
>
Collection
public
virtual
IMongoDatabase
Database
=>
_databaseProvider
.
Database
;
public
virtual
IMongoCollection
<
TEntity
>
Collection
{
get
{
return
_databaseProvider
.
Database
.
GetCollection
<
TEntity
>(
typeof
(
TEntity
).
Name
);
string
name
=
CollectionName
;
if
(
CollectionName
.
IsNullOrEmpty
())
{
name
=
typeof
(
TEntity
).
Name
;
}
return
_databaseProvider
.
Database
.
GetCollection
<
TEntity
>(
name
,
null
);
}
}
p
rivate
readonly
IMongoDatabaseProvider
_databaseProvider
;
p
ublic
abstract
string
CollectionName
{
get
;
}
public
MongoDbRepositoryBase
(
IMongoDatabaseProvider
databaseProvider
)
{
...
...
@@ -55,7 +58,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
One
(
query
);
var
entity
=
Collection
.
Find
(
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