├── .gitignore ├── Sample.Web ├── App_Start │ ├── Startup.Autofac.cs │ └── Startup.WebApi.cs ├── Controllers │ └── PeopleController.cs ├── Infrastructure │ ├── AutofacValidatorFactory.cs │ └── AutofacWebModule.cs ├── Models │ ├── Person.cs │ └── PersonValidator.cs ├── Properties │ └── AssemblyInfo.cs ├── Sample.Web.csproj ├── Startup.cs ├── Web.Debug.config ├── Web.Release.config ├── Web.config └── packages.config └── Sample.sln /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studo 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | *_i.c 42 | *_p.c 43 | *_i.h 44 | *.ilk 45 | *.meta 46 | *.obj 47 | *.pch 48 | *.pdb 49 | *.pgc 50 | *.pgd 51 | *.rsp 52 | *.sbr 53 | *.tlb 54 | *.tli 55 | *.tlh 56 | *.tmp 57 | *.tmp_proj 58 | *.log 59 | *.vspscc 60 | *.vssscc 61 | .builds 62 | *.pidb 63 | *.svclog 64 | *.scc 65 | 66 | # Chutzpah Test files 67 | _Chutzpah* 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | *.cachefile 76 | 77 | # Visual Studio profiler 78 | *.psess 79 | *.vsp 80 | *.vspx 81 | 82 | # TFS 2012 Local Workspace 83 | $tf/ 84 | 85 | # Guidance Automation Toolkit 86 | *.gpState 87 | 88 | # ReSharper is a .NET coding add-in 89 | _ReSharper*/ 90 | *.[Rr]e[Ss]harper 91 | *.DotSettings.user 92 | 93 | # JustCode is a .NET coding addin-in 94 | .JustCode 95 | 96 | # TeamCity is a build add-in 97 | _TeamCity* 98 | 99 | # DotCover is a Code Coverage Tool 100 | *.dotCover 101 | 102 | # NCrunch 103 | _NCrunch_* 104 | .*crunch*.local.xml 105 | 106 | # MightyMoose 107 | *.mm.* 108 | AutoTest.Net/ 109 | 110 | # Web workbench (sass) 111 | .sass-cache/ 112 | 113 | # Installshield output folder 114 | [Ee]xpress/ 115 | 116 | # DocProject is a documentation generator add-in 117 | DocProject/buildhelp/ 118 | DocProject/Help/*.HxT 119 | DocProject/Help/*.HxC 120 | DocProject/Help/*.hhc 121 | DocProject/Help/*.hhk 122 | DocProject/Help/*.hhp 123 | DocProject/Help/Html2 124 | DocProject/Help/html 125 | 126 | # Click-Once directory 127 | publish/ 128 | 129 | # Publish Web Output 130 | *.[Pp]ublish.xml 131 | *.azurePubxml 132 | # TODO: Comment the next line if you want to checkin your web deploy settings 133 | # but database connection strings (with potential passwords) will be unencrypted 134 | *.pubxml 135 | *.publishproj 136 | 137 | # NuGet Packages 138 | *.nupkg 139 | # The packages folder can be ignored because of Package Restore 140 | **/packages/* 141 | # except build/, which is used as an MSBuild target. 142 | !**/packages/build/ 143 | # Uncomment if necessary however generally it will be regenerated when needed 144 | #!**/packages/repositories.config 145 | 146 | # Windows Azure Build Output 147 | csx/ 148 | *.build.csdef 149 | 150 | # Windows Store app package directory 151 | AppPackages/ 152 | 153 | # Others 154 | *.[Cc]ache 155 | ClientBin/ 156 | [Ss]tyle[Cc]op.* 157 | ~$* 158 | *~ 159 | *.dbmdl 160 | *.dbproj.schemaview 161 | *.pfx 162 | *.publishsettings 163 | node_modules/ 164 | bower_components/ 165 | 166 | # RIA/Silverlight projects 167 | Generated_Code/ 168 | 169 | # Backup & report files from converting an old project file 170 | # to a newer Visual Studio version. Backup files are not needed, 171 | # because we have git ;-) 172 | _UpgradeReport_Files/ 173 | Backup*/ 174 | UpgradeLog*.XML 175 | UpgradeLog*.htm 176 | 177 | # SQL Server files 178 | *.mdf 179 | *.ldf 180 | 181 | # Business Intelligence projects 182 | *.rdl.data 183 | *.bim.layout 184 | *.bim_*.settings 185 | 186 | # Microsoft Fakes 187 | FakesAssemblies/ 188 | 189 | # Node.js Tools for Visual Studio 190 | .ntvs_analysis.dat 191 | 192 | # Visual Studio 6 build log 193 | *.plg 194 | 195 | # Visual Studio 6 workspace options file 196 | *.opt 197 | -------------------------------------------------------------------------------- /Sample.Web/App_Start/Startup.Autofac.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using Autofac.Features.ResolveAnything; 3 | using Sample.Web.Infrastructure; 4 | 5 | namespace Sample.Web 6 | { 7 | public partial class Startup 8 | { 9 | private static IContainer ConfigureAutofac() 10 | { 11 | var builder = new ContainerBuilder(); 12 | 13 | builder.RegisterModule(); 14 | builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource()); 15 | 16 | var container = builder.Build(); 17 | return container; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Sample.Web/App_Start/Startup.WebApi.cs: -------------------------------------------------------------------------------- 1 | using System.Net.Http.Formatting; 2 | using System.Web.Http; 3 | using Autofac; 4 | using Autofac.Integration.WebApi; 5 | using Newtonsoft.Json; 6 | using Newtonsoft.Json.Serialization; 7 | using Owin; 8 | 9 | namespace Sample.Web 10 | { 11 | public partial class Startup 12 | { 13 | private static void ConfigureWebApi(IAppBuilder app, IContainer container) 14 | { 15 | var configuration = new HttpConfiguration(); 16 | app.UseWebApi(configuration); 17 | 18 | // Web API configuration and services 19 | configuration.Formatters.Clear(); 20 | configuration.Formatters.Add(new JsonMediaTypeFormatter()); 21 | configuration.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented; 22 | configuration.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); 23 | 24 | // Web API routes 25 | configuration.MapHttpAttributeRoutes(); 26 | 27 | configuration.Routes.MapHttpRoute( 28 | name: "DefaultApi", 29 | routeTemplate: "api/{controller}/{id}", 30 | defaults: new { id = RouteParameter.Optional } 31 | ); 32 | 33 | configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Sample.Web/Controllers/PeopleController.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Http; 2 | using Sample.Web.Models; 3 | 4 | namespace Sample.Web.Controllers 5 | { 6 | public class PeopleController : ApiController 7 | { 8 | public IHttpActionResult CreatePerson(Person person) 9 | { 10 | if (!ModelState.IsValid) 11 | { 12 | return BadRequest(ModelState); 13 | } 14 | 15 | return Ok(); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Sample.Web/Infrastructure/AutofacValidatorFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Autofac; 3 | using FluentValidation; 4 | 5 | namespace Sample.Web.Infrastructure 6 | { 7 | public class AutofacValidatorFactory : ValidatorFactoryBase 8 | { 9 | private readonly IComponentContext _context; 10 | 11 | public AutofacValidatorFactory(IComponentContext context) 12 | { 13 | _context = context; 14 | } 15 | 16 | public override IValidator CreateInstance(Type validatorType) 17 | { 18 | object instance; 19 | if (_context.TryResolve(validatorType, out instance)) 20 | { 21 | var validator = instance as IValidator; 22 | return validator; 23 | } 24 | 25 | return null; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Sample.Web/Infrastructure/AutofacWebModule.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Http.Validation; 2 | using Autofac; 3 | using Autofac.Integration.WebApi; 4 | using FluentValidation; 5 | using FluentValidation.WebApi; 6 | 7 | namespace Sample.Web.Infrastructure 8 | { 9 | public class AutofacWebModule : Module 10 | { 11 | protected override void Load(ContainerBuilder builder) 12 | { 13 | builder.RegisterApiControllers(ThisAssembly); 14 | 15 | builder.RegisterAssemblyTypes(ThisAssembly) 16 | .Where(t => t.Name.EndsWith("Validator")) 17 | .AsImplementedInterfaces() 18 | .InstancePerLifetimeScope(); 19 | 20 | builder.RegisterType().As(); 21 | 22 | builder.RegisterType().As().SingleInstance(); 23 | 24 | base.Load(builder); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Sample.Web/Models/Person.cs: -------------------------------------------------------------------------------- 1 | namespace Sample.Web.Models 2 | { 3 | public class Person 4 | { 5 | public string FirstName { get; set; } 6 | public string OtherNames { get; set; } 7 | public string LastName { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /Sample.Web/Models/PersonValidator.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation; 2 | 3 | namespace Sample.Web.Models 4 | { 5 | public class PersonValidator : AbstractValidator 6 | { 7 | public PersonValidator() 8 | { 9 | RuleFor(x => x.FirstName).NotEmpty(); 10 | RuleFor(x => x.LastName).NotEmpty(); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Sample.Web/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Sample.Web")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Sample.Web")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("e9259b3b-5cf6-4a0c-af8e-112201c28159")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /Sample.Web/Sample.Web.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Debug 8 | AnyCPU 9 | 10 | 11 | 2.0 12 | {E9259B3B-5CF6-4A0C-AF8E-112201C28159} 13 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 14 | Library 15 | Properties 16 | Sample.Web 17 | Sample.Web 18 | v4.5.2 19 | true 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | true 30 | full 31 | false 32 | bin\ 33 | DEBUG;TRACE 34 | prompt 35 | 4 36 | 37 | 38 | pdbonly 39 | true 40 | bin\ 41 | TRACE 42 | prompt 43 | 4 44 | 45 | 46 | 47 | ..\packages\Antlr.3.4.1.9004\lib\Antlr3.Runtime.dll 48 | True 49 | 50 | 51 | ..\packages\Autofac.3.5.2\lib\net40\Autofac.dll 52 | True 53 | 54 | 55 | ..\packages\Autofac.WebApi2.3.4.0\lib\net45\Autofac.Integration.WebApi.dll 56 | True 57 | 58 | 59 | ..\packages\FluentValidation.5.6.2.0\lib\Net45\FluentValidation.dll 60 | True 61 | 62 | 63 | ..\packages\FluentValidation.WebApi.5.6.2.0\lib\Net45\FluentValidation.WebApi.dll 64 | True 65 | 66 | 67 | ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll 68 | True 69 | 70 | 71 | 72 | ..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll 73 | True 74 | 75 | 76 | ..\packages\Microsoft.Owin.Host.SystemWeb.3.0.1\lib\net45\Microsoft.Owin.Host.SystemWeb.dll 77 | True 78 | 79 | 80 | ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll 81 | True 82 | 83 | 84 | ..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll 85 | True 86 | 87 | 88 | ..\packages\Owin.1.0\lib\net40\Owin.dll 89 | True 90 | 91 | 92 | 93 | ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll 94 | True 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll 107 | True 108 | 109 | 110 | ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll 111 | True 112 | 113 | 114 | ..\packages\Microsoft.AspNet.WebApi.Owin.5.2.3\lib\net45\System.Web.Http.Owin.dll 115 | True 116 | 117 | 118 | ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.3\lib\net45\System.Web.Http.WebHost.dll 119 | True 120 | 121 | 122 | ..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll 123 | True 124 | 125 | 126 | ..\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll 127 | True 128 | 129 | 130 | ..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll 131 | True 132 | 133 | 134 | ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.dll 135 | True 136 | 137 | 138 | ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Deployment.dll 139 | True 140 | 141 | 142 | ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll 143 | True 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | ..\packages\WebGrease.1.5.2\lib\WebGrease.dll 154 | True 155 | 156 | 157 | 158 | 159 | 160 | Web.config 161 | 162 | 163 | Web.config 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 10.0 183 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | True 193 | True 194 | 51032 195 | / 196 | http://localhost:51032/ 197 | False 198 | False 199 | 200 | 201 | False 202 | 203 | 204 | 205 | 206 | 207 | 208 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 209 | 210 | 211 | 212 | 213 | 220 | -------------------------------------------------------------------------------- /Sample.Web/Startup.cs: -------------------------------------------------------------------------------- 1 | using Owin; 2 | 3 | namespace Sample.Web 4 | { 5 | public partial class Startup 6 | { 7 | public void Configuration(IAppBuilder app) 8 | { 9 | var container = ConfigureAutofac(); 10 | ConfigureWebApi(app, container); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Sample.Web/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | -------------------------------------------------------------------------------- /Sample.Web/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | -------------------------------------------------------------------------------- /Sample.Web/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /Sample.Web/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Sample.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.Web", "Sample.Web\Sample.Web.csproj", "{E9259B3B-5CF6-4A0C-AF8E-112201C28159}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {E9259B3B-5CF6-4A0C-AF8E-112201C28159}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {E9259B3B-5CF6-4A0C-AF8E-112201C28159}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {E9259B3B-5CF6-4A0C-AF8E-112201C28159}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {E9259B3B-5CF6-4A0C-AF8E-112201C28159}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | --------------------------------------------------------------------------------