Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CleanArchitecture
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
CleanArchitecture
Commits
f7b373d1
Commit
f7b373d1
authored
Dec 03, 2018
by
Steve Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sqlite working with file in root of web
parent
4d9bb48d
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
181 additions
and
4 deletions
+181
-4
CleanArchitecture.Infrastructure.csproj
...re.Infrastructure/CleanArchitecture.Infrastructure.csproj
+2
-0
AppDbContext.cs
src/CleanArchitecture.Infrastructure/Data/AppDbContext.cs
+8
-0
20181203222230_InitialModel.Designer.cs
...e/Data/Migrations/20181203222230_InitialModel.Designer.cs
+38
-0
20181203222230_InitialModel.cs
...astructure/Data/Migrations/20181203222230_InitialModel.cs
+31
-0
AppDbContextModelSnapshot.cs
...frastructure/Data/Migrations/AppDbContextModelSnapshot.cs
+36
-0
CleanArchitecture.Web.csproj
src/CleanArchitecture.Web/CleanArchitecture.Web.csproj
+2
-0
Program.cs
src/CleanArchitecture.Web/Program.cs
+27
-2
SeedData.cs
src/CleanArchitecture.Web/SeedData.cs
+29
-0
Startup.cs
src/CleanArchitecture.Web/Startup.cs
+5
-1
web.config
src/CleanArchitecture.Web/web.config
+3
-1
No files found.
src/CleanArchitecture.Infrastructure/CleanArchitecture.Infrastructure.csproj
View file @
f7b373d1
...
@@ -12,9 +12,11 @@
...
@@ -12,9 +12,11 @@
<ItemGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="4.8.1" />
<PackageReference Include="Autofac" Version="4.8.1" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.5" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.4" PrivateAssets="all">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.4" PrivateAssets="all">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.4" />
<PackageReference Include="SQLite" Version="3.13.0" />
</ItemGroup>
</ItemGroup>
</Project>
</Project>
src/CleanArchitecture.Infrastructure/Data/AppDbContext.cs
View file @
f7b373d1
...
@@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
...
@@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
using
System.Linq
;
using
System.Linq
;
using
CleanArchitecture.Core.Entities
;
using
CleanArchitecture.Core.Entities
;
using
CleanArchitecture.Core.SharedKernel
;
using
CleanArchitecture.Core.SharedKernel
;
using
JetBrains.Annotations
;
namespace
CleanArchitecture.Infrastructure.Data
namespace
CleanArchitecture.Infrastructure.Data
{
{
...
@@ -10,6 +11,10 @@ namespace CleanArchitecture.Infrastructure.Data
...
@@ -10,6 +11,10 @@ namespace CleanArchitecture.Infrastructure.Data
{
{
private
readonly
IDomainEventDispatcher
_dispatcher
;
private
readonly
IDomainEventDispatcher
_dispatcher
;
public
AppDbContext
(
DbContextOptions
options
)
:
base
(
options
)
{
}
public
AppDbContext
(
DbContextOptions
<
AppDbContext
>
options
,
IDomainEventDispatcher
dispatcher
)
public
AppDbContext
(
DbContextOptions
<
AppDbContext
>
options
,
IDomainEventDispatcher
dispatcher
)
:
base
(
options
)
:
base
(
options
)
{
{
...
@@ -22,6 +27,9 @@ namespace CleanArchitecture.Infrastructure.Data
...
@@ -22,6 +27,9 @@ namespace CleanArchitecture.Infrastructure.Data
{
{
int
result
=
base
.
SaveChanges
();
int
result
=
base
.
SaveChanges
();
// ignore events if no dispatcher provided
if
(
_dispatcher
==
null
)
return
result
;
// dispatch events only if save was successful
// dispatch events only if save was successful
var
entitiesWithEvents
=
ChangeTracker
.
Entries
<
BaseEntity
>()
var
entitiesWithEvents
=
ChangeTracker
.
Entries
<
BaseEntity
>()
.
Select
(
e
=>
e
.
Entity
)
.
Select
(
e
=>
e
.
Entity
)
...
...
src/CleanArchitecture.Infrastructure/Data/Migrations/20181203222230_InitialModel.Designer.cs
0 → 100644
View file @
f7b373d1
// <auto-generated />
using
CleanArchitecture.Infrastructure.Data
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.EntityFrameworkCore.Migrations
;
using
Microsoft.EntityFrameworkCore.Storage.ValueConversion
;
namespace
CleanArchitecture.Infrastructure.Data.Migrations
{
[
DbContext
(
typeof
(
AppDbContext
))]
[
Migration
(
"20181203222230_InitialModel"
)]
partial
class
InitialModel
{
protected
override
void
BuildTargetModel
(
ModelBuilder
modelBuilder
)
{
#pragma warning disable 612, 618
modelBuilder
.
HasAnnotation
(
"ProductVersion"
,
"2.1.4-rtm-31024"
);
modelBuilder
.
Entity
(
"CleanArchitecture.Core.Entities.ToDoItem"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
();
b
.
Property
<
string
>(
"Description"
);
b
.
Property
<
bool
>(
"IsDone"
);
b
.
Property
<
string
>(
"Title"
);
b
.
HasKey
(
"Id"
);
b
.
ToTable
(
"ToDoItems"
);
});
#pragma warning restore 612, 618
}
}
}
src/CleanArchitecture.Infrastructure/Data/Migrations/20181203222230_InitialModel.cs
0 → 100644
View file @
f7b373d1
using
Microsoft.EntityFrameworkCore.Migrations
;
namespace
CleanArchitecture.Infrastructure.Data.Migrations
{
public
partial
class
InitialModel
:
Migration
{
protected
override
void
Up
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
CreateTable
(
name
:
"ToDoItems"
,
columns
:
table
=>
new
{
Id
=
table
.
Column
<
int
>(
nullable
:
false
)
.
Annotation
(
"Sqlite:Autoincrement"
,
true
),
Title
=
table
.
Column
<
string
>(
nullable
:
true
),
Description
=
table
.
Column
<
string
>(
nullable
:
true
),
IsDone
=
table
.
Column
<
bool
>(
nullable
:
false
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_ToDoItems"
,
x
=>
x
.
Id
);
});
}
protected
override
void
Down
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
DropTable
(
name
:
"ToDoItems"
);
}
}
}
src/CleanArchitecture.Infrastructure/Data/Migrations/AppDbContextModelSnapshot.cs
0 → 100644
View file @
f7b373d1
// <auto-generated />
using
CleanArchitecture.Infrastructure.Data
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.EntityFrameworkCore.Storage.ValueConversion
;
namespace
CleanArchitecture.Infrastructure.Data.Migrations
{
[
DbContext
(
typeof
(
AppDbContext
))]
partial
class
AppDbContextModelSnapshot
:
ModelSnapshot
{
protected
override
void
BuildModel
(
ModelBuilder
modelBuilder
)
{
#pragma warning disable 612, 618
modelBuilder
.
HasAnnotation
(
"ProductVersion"
,
"2.1.4-rtm-31024"
);
modelBuilder
.
Entity
(
"CleanArchitecture.Core.Entities.ToDoItem"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
();
b
.
Property
<
string
>(
"Description"
);
b
.
Property
<
bool
>(
"IsDone"
);
b
.
Property
<
string
>(
"Title"
);
b
.
HasKey
(
"Id"
);
b
.
ToTable
(
"ToDoItems"
);
});
#pragma warning restore 612, 618
}
}
}
src/CleanArchitecture.Web/CleanArchitecture.Web.csproj
View file @
f7b373d1
...
@@ -23,11 +23,13 @@
...
@@ -23,11 +23,13 @@
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.3.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.3.0" />
<PackageReference Include="Dapper" Version="1.50.5" />
<PackageReference Include="Dapper" Version="1.50.5" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.5" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.4" PrivateAssets="all">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.4" PrivateAssets="all">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.5" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.5" PrivateAssets="All" />
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="1.0.163" />
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="1.0.163" />
<PackageReference Include="SQLite" Version="3.13.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="3.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="3.0.0" />
</ItemGroup>
</ItemGroup>
...
...
src/CleanArchitecture.Web/Program.cs
View file @
f7b373d1
using
Microsoft.AspNetCore
;
using
CleanArchitecture.Infrastructure.Data
;
using
Microsoft.AspNetCore
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.Logging
;
using
System
;
namespace
CleanArchitecture.Web
namespace
CleanArchitecture.Web
{
{
...
@@ -7,7 +12,27 @@ namespace CleanArchitecture.Web
...
@@ -7,7 +12,27 @@ namespace CleanArchitecture.Web
{
{
public
static
void
Main
(
string
[]
args
)
public
static
void
Main
(
string
[]
args
)
{
{
CreateWebHostBuilder
(
args
).
Build
().
Run
();
var
host
=
CreateWebHostBuilder
(
args
).
Build
();
using
(
var
scope
=
host
.
Services
.
CreateScope
())
{
var
services
=
scope
.
ServiceProvider
;
try
{
var
context
=
services
.
GetRequiredService
<
AppDbContext
>();
// context.Database.Migrate();
context
.
Database
.
EnsureCreated
();
SeedData
.
Initialize
(
services
);
}
catch
(
Exception
ex
)
{
var
logger
=
services
.
GetRequiredService
<
ILogger
<
Program
>>();
logger
.
LogError
(
ex
,
"An error occurred seeding the DB."
);
}
}
host
.
Run
();
}
}
public
static
IWebHostBuilder
CreateWebHostBuilder
(
string
[]
args
)
=>
public
static
IWebHostBuilder
CreateWebHostBuilder
(
string
[]
args
)
=>
...
...
src/CleanArchitecture.Web/SeedData.cs
View file @
f7b373d1
using
CleanArchitecture.Core.Entities
;
using
CleanArchitecture.Core.Entities
;
using
CleanArchitecture.Infrastructure.Data
;
using
CleanArchitecture.Infrastructure.Data
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.Extensions.DependencyInjection
;
using
System
;
using
System.Linq
;
namespace
CleanArchitecture.Web
namespace
CleanArchitecture.Web
{
{
public
static
class
SeedData
public
static
class
SeedData
{
{
public
static
void
Initialize
(
IServiceProvider
serviceProvider
)
{
using
(
var
dbContext
=
new
AppDbContext
(
serviceProvider
.
GetRequiredService
<
DbContextOptions
<
AppDbContext
>>()))
{
// Look for any TODO items.
if
(
dbContext
.
ToDoItems
.
Any
())
{
return
;
// DB has been seeded
}
dbContext
.
ToDoItems
.
Add
(
new
ToDoItem
()
{
Title
=
"Test Item 1"
,
Description
=
"Test Description One"
});
dbContext
.
ToDoItems
.
Add
(
new
ToDoItem
()
{
Title
=
"Test Item 2"
,
Description
=
"Test Description Two"
});
dbContext
.
SaveChanges
();
}
}
public
static
void
PopulateTestData
(
AppDbContext
dbContext
)
public
static
void
PopulateTestData
(
AppDbContext
dbContext
)
{
{
var
toDos
=
dbContext
.
ToDoItems
;
var
toDos
=
dbContext
.
ToDoItems
;
...
...
src/CleanArchitecture.Web/Startup.cs
View file @
f7b373d1
...
@@ -35,8 +35,12 @@ namespace CleanArchitecture.Web
...
@@ -35,8 +35,12 @@ namespace CleanArchitecture.Web
});
});
// TODO: Add DbContext and IOC
// TODO: Add DbContext and IOC
string
dbName
=
Guid
.
NewGuid
().
ToString
();
string
dbName
=
Guid
.
NewGuid
().
ToString
();
// create schema before using:
// https://www.meziantou.net/2017/09/11/testing-ef-core-in-memory-using-sqlite
services
.
AddDbContext
<
AppDbContext
>(
options
=>
services
.
AddDbContext
<
AppDbContext
>(
options
=>
options
.
UseInMemoryDatabase
(
dbName
));
options
.
UseSqlite
(
"Data Source=database.sqlite"
));
// options.UseInMemoryDatabase(dbName));
//options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
//options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services
.
AddMvc
()
services
.
AddMvc
()
...
...
src/CleanArchitecture.Web/web.config
View file @
f7b373d1
...
@@ -7,6 +7,8 @@
...
@@ -7,6 +7,8 @@
<
handlers
>
<
handlers
>
<
add
name
=
"aspNetCore"
path
=
"*"
verb
=
"*"
modules
=
"AspNetCoreModule"
resourceType
=
"Unspecified"
/>
<
add
name
=
"aspNetCore"
path
=
"*"
verb
=
"*"
modules
=
"AspNetCoreModule"
resourceType
=
"Unspecified"
/>
</
handlers
>
</
handlers
>
<
aspNetCore
processPath
=
"%LAUNCHER_PATH%"
arguments
=
"%LAUNCHER_ARGS%"
stdoutLogEnabled
=
"false"
stdoutLogFile
=
".\logs\stdout"
forwardWindowsAuthToken
=
"false"
startupTimeLimit
=
"3600"
requestTimeout
=
"23:00:00"
/>
<
aspNetCore
processPath
=
"%LAUNCHER_PATH%"
arguments
=
"%LAUNCHER_ARGS%"
stdoutLogEnabled
=
"false"
stdoutLogFile
=
".\logs\stdout"
forwardWindowsAuthToken
=
"false"
startupTimeLimit
=
"3600"
requestTimeout
=
"23:00:00"
>
<
environmentVariables
/>
</
aspNetCore
>
</
system
.
webServer
>
</
system
.
webServer
>
</
configuration
>
</
configuration
>
\ No newline at end of file
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