- nuget から Ninject.MVC3 パッケージをダウンロードします。
- AppStart フォルダーから「ninject web common」部分を削除します
- global.asax を開き、コードを次のように変更します。
namespace OnBoardingMVC
{
public class MvcApplication : Ninject.Web.Common.NinjectHttpApplication
{
protected override IKernel CreateKernel()
{
var kernel = new StandardKernel();
NinjectConfig.RegisterServices(kernel);
return kernel;
}
protected override void OnApplicationStarted()
{
base.OnApplicationStarted();
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
}
次に、App_Start フォルダーに新しい NinjectConfig.cs ファイルを作成し、次のコードをクラスに追加します。
namespace OnBoardingMVC
{
public class NinjectConfig
{
public static void RegisterServices(IKernel kernel)
{
// e.g. kernel.Load(Assembly.GetExecutingAssembly());
kernel.Bind(typeof(IEmployeeUow))
.To(typeof(EmployeeUow))
.WithConstructorArgument("adapter", <Add new AdapterVariable here>)
;
}
}
}
次に、EmployeeUow
クラスから継承するクラスを作成し、から継承する をUnitOfWork
作成することもできます。コンテキスト アダプターはコンストラクターのパラメーターになり、そのコンストラクターはアダプターをクラスの基本コンストラクターにも渡します。IEmployeeUow
IUnitOfWork
UnitOfWork