Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file added EF.DI/EF.DI/.vs/EF.DI/v15/.suo
Binary file not shown.
Binary file added EF.DI/EF.DI/.vs/EF.DI/v15/sqlite3/storage.ide
Binary file not shown.
1,039 changes: 1,039 additions & 0 deletions EF.DI/EF.DI/.vs/config/applicationhost.config

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions EF.DI/EF.DI/EF.Core/BaseEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
namespace EF.Core
{
public abstract class BaseEntity
{
public Int64 ID { get; set; }
public DateTime CreatedTime { get; set; }
public DateTime ModifiedTime { get; set; }
public string IP { get; set; }
}
}
11 changes: 11 additions & 0 deletions EF.DI/EF.DI/EF.Core/Data/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
namespace EF.Core.Data
{
public class User : BaseEntity
{
public string UserName { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public virtual UserProfile UserProfile { get; set; }
}
}
10 changes: 10 additions & 0 deletions EF.DI/EF.DI/EF.Core/Data/UserProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace EF.Core.Data
{
public class UserProfile : BaseEntity
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Address { get; set; }
public virtual User User { get; set; }
}
}
49 changes: 49 additions & 0 deletions EF.DI/EF.DI/EF.Core/EF.Core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2147CBF8-E1CA-4CED-92CD-66BC4FC6FC58}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EF.Core</RootNamespace>
<AssemblyName>EF.Core</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BaseEntity.cs" />
<Compile Include="Data\User.cs" />
<Compile Include="Data\UserProfile.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
36 changes: 36 additions & 0 deletions EF.DI/EF.DI/EF.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("EF.Core")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EF.Core")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("2147cbf8-e1ca-4ced-92cd-66bc4fc6fc58")]

// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Binary file added EF.DI/EF.DI/EF.Core/bin/Debug/EF.Core.dll
Binary file not shown.
Binary file added EF.DI/EF.DI/EF.Core/bin/Debug/EF.Core.pdb
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2e832418b8aa291bfce459e356cf73e7069bfc47
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
D:\Visual Studio 2015\Projects\EF.DI\EF.Core\bin\Debug\EF.Core.dll
D:\Visual Studio 2015\Projects\EF.DI\EF.Core\bin\Debug\EF.Core.pdb
D:\Visual Studio 2015\Projects\EF.DI\EF.Core\obj\Debug\EF.Core.csprojResolveAssemblyReference.cache
D:\Visual Studio 2015\Projects\EF.DI\EF.Core\obj\Debug\EF.Core.csproj.CoreCompileInputs.cache
D:\Visual Studio 2015\Projects\EF.DI\EF.Core\obj\Debug\EF.Core.dll
D:\Visual Studio 2015\Projects\EF.DI\EF.Core\obj\Debug\EF.Core.pdb
Binary file not shown.
Binary file added EF.DI/EF.DI/EF.Core/obj/Debug/EF.Core.dll
Binary file not shown.
Binary file added EF.DI/EF.DI/EF.Core/obj/Debug/EF.Core.pdb
Binary file not shown.
43 changes: 43 additions & 0 deletions EF.DI/EF.DI/EF.DI.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EF.DI", "EF.DI\EF.DI.csproj", "{FF2E6A6B-8122-4C74-B522-FF8B1B627FB1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EF.Core", "EF.Core\EF.Core.csproj", "{2147CBF8-E1CA-4CED-92CD-66BC4FC6FC58}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EF.Data", "EF.Data\EF.Data.csproj", "{31C5599B-CDD8-4C68-8ED4-CE48C46DC471}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EF.Service", "EF.Service\EF.Service.csproj", "{A20EFD82-FBAF-4560-A3A8-65615FE10533}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FF2E6A6B-8122-4C74-B522-FF8B1B627FB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF2E6A6B-8122-4C74-B522-FF8B1B627FB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF2E6A6B-8122-4C74-B522-FF8B1B627FB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF2E6A6B-8122-4C74-B522-FF8B1B627FB1}.Release|Any CPU.Build.0 = Release|Any CPU
{2147CBF8-E1CA-4CED-92CD-66BC4FC6FC58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2147CBF8-E1CA-4CED-92CD-66BC4FC6FC58}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2147CBF8-E1CA-4CED-92CD-66BC4FC6FC58}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2147CBF8-E1CA-4CED-92CD-66BC4FC6FC58}.Release|Any CPU.Build.0 = Release|Any CPU
{31C5599B-CDD8-4C68-8ED4-CE48C46DC471}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{31C5599B-CDD8-4C68-8ED4-CE48C46DC471}.Debug|Any CPU.Build.0 = Debug|Any CPU
{31C5599B-CDD8-4C68-8ED4-CE48C46DC471}.Release|Any CPU.ActiveCfg = Release|Any CPU
{31C5599B-CDD8-4C68-8ED4-CE48C46DC471}.Release|Any CPU.Build.0 = Release|Any CPU
{A20EFD82-FBAF-4560-A3A8-65615FE10533}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A20EFD82-FBAF-4560-A3A8-65615FE10533}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A20EFD82-FBAF-4560-A3A8-65615FE10533}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A20EFD82-FBAF-4560-A3A8-65615FE10533}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {90E95B1A-7D78-4113-8A2D-D16166135FC4}
EndGlobalSection
EndGlobal
32 changes: 32 additions & 0 deletions EF.DI/EF.DI/EF.DI/App_Start/AutofacConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Autofac;
using Autofac.Integration.Mvc;
using EF.DI.Autofac;
using System.Web.Mvc;

namespace EF.DI.App_Start
{
public class AutofacConfig
{
public static void ConfigureContainer()
{
var builder = new ContainerBuilder();

// 在控制器中注册依赖
builder.RegisterControllers(typeof(MvcApplication).Assembly);

// 在过滤中注册依赖
builder.RegisterFilterProvider();

// 在自定义视图中注册依赖
builder.RegisterSource(new ViewRegistrationSource());

// 注册我们自定义依赖
builder.RegisterModule(new AutofacModule());

var container = builder.Build();

// 设置Autofac容器到MVC依赖关系中
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
}
}
}
18 changes: 18 additions & 0 deletions EF.DI/EF.DI/EF.DI/App_Start/BundleConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Web;
using System.Web.Optimization;

namespace EF.DI
{
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));

bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
}
}
}
13 changes: 13 additions & 0 deletions EF.DI/EF.DI/EF.DI/App_Start/FilterConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Web;
using System.Web.Mvc;

namespace EF.DI
{
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
}
}
23 changes: 23 additions & 0 deletions EF.DI/EF.DI/EF.DI/App_Start/RouteConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace EF.DI
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "User", action = "Index", id = UrlParameter.Optional }
);
}
}
}
19 changes: 19 additions & 0 deletions EF.DI/EF.DI/EF.DI/Autofac/AutofacModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Autofac;
using EF.Data;
using EF.Service;

namespace EF.DI.Autofac
{
public class AutofacModule : Module
{
protected override void Load(ContainerBuilder builder)
{

builder.RegisterType<EFDbContext>().As<IDbContext>().InstancePerLifetimeScope();
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>)).InstancePerLifetimeScope();
builder.RegisterType<UserService>().As<IUserService>();

base.Load(builder);
}
}
}
Loading