This repository contains a collection of infrastructure projects that should be added as a submodule inside of another repository.
- Go do a Git repository where you'd like to add these infrastructure projects.
- Add this repository as a submodule:
git submodule add https://github.com/bcjobs/infra.git Infra
- Open Solution in Visual Studio.
- Right-click solution name and select:
Add
-->New Solution Folder
- Name the solution folder
Infra
- One by one, add all of the projects in the submodule into the solution.
- If you encounter any problems with Entity Framework dependencies while trying to build one of these added projects, uninstall and re-install Entity Framework Nuget packages.
- Add references too all projects in
Infra
folder to any project that will need them (e.g. web project).
- Register all IHandlers in Infra and web project with Autofac
- Example: https://github.com/bcjobs/demo/blob/master/Demo.Web/App_Start/AutofacConfig.cs
- Create OwinConfig:
- In
App_Start
folder of web project, add an OwinConfig class: - https://github.com/bcjobs/demo/blob/master/Demo.Web/App_Start/OwinConfig.cs
- In
- Register OwinConfig:
- Add the following to
appSettings
inweb.config
:<add key="owin:AppStartup" value="{namespace}.OwinConfig" />
- Where
{namespace}
is the namespace toOwinConfig
- Add the following to
- Optionally add the following options in
web.config
appSettings
:<add key="authentications:LoginPath" value="/authentication/login" />
<add key="authentications:IgnoreLoginPathIfRequestUrlStartsWithSegment" value="/api" />
This is very important to add ifauthentications:LoginPath
is added, otherwise 401 responses from the API will result in undesirable 302 redirects.<add key="authentications:CookieName" value="auth-token" />
<add key="authentications:CookieSecure" value="SameAsRequest" />
Where value can beSameAsRequest
(default),Never
, orAlways
- Add the following NuGet packages to the web project:
- Microsoft.AspNet.Identity.EntityFramework
- Microsoft.AspNet.Identity.OWIN
- Implement Infra.Authentications.IUserLookup
- Implement Infra.Authentications.IAuthenticator
- Add
AuthenticationsIdentity
connection string inweb.config
.
These are recommendations only and not required to use this library.
Every time you add a new project, these changes to the project properties are recommended:
Build
tab:Configurations
:All Configurations
Supress warnings
:1998
If Code Contracts is installed:
Code Contracts
tab:Configurations
:All Configurations
Perform Runtime Contract Checking
: select checkbox and selectFull
from the dropdownContract Reference Assembly
:Build
Emit contracts into XML doc file
: select checkbox
To ensure that all implementations of interfaces in a project are auto-discovered, do the following:
- Open
AssemblyInfo.cs
file (nested insideProperties
in Solution Explorer) - Add this to the bottom:
[assembly: IoC]
- Don't forget the using statement at the top:
using Infra.IoC;