public void NinjectResolver_DoesNot_Resolve_NonRegistered_ContactRepository_Test()
        {
            var kernel = new StandardKernel();

            var resolver = new NinjectResolver(kernel);
            var instance = resolver.GetService(typeof(IContactRepository));

            Assert.IsNull(instance);
        }
        public void NinjectResolver_Resolves_Registered_ContactRepository_Test()
        {
            var kernel = new StandardKernel();
            kernel.Bind<IContactRepository>().ToConstant(new InMemoryContactRepository());

            var resolver = new NinjectResolver(kernel);
            var instance = resolver.GetService(typeof(IContactRepository));

            Assert.IsNotNull(instance);
        }
Пример #3
0
        public static void RegisterDependencyResolver()
        {
            var kernal = new StandardKernel();
            kernal.Bind<ICountryReferenceDataRepository>().To<AzureCountryReferenceDataRepository>();

            string currenciesFileName = HostingEnvironment.MapPath(@"~\Resources\iso_4217_currencies.csv");
            kernal.Bind<ICurrencyReferenceDataRepository>().To<FlatFileCurrencyReferenceDataRepository>()
                .WithConstructorArgument("fileName", currenciesFileName);

            var dependencyResolver = new NinjectResolver(kernal);
            GlobalConfiguration.Configuration.DependencyResolver = dependencyResolver;
        }
Пример #4
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            //DI
            IKernel kernel = new StandardKernel();
            kernel.Bind<IPaisRepository>().To<PaisRepository>();
            System.Web.Http.Dependencies.IDependencyResolver resolver = new NinjectResolver(kernel);
            GlobalConfiguration.Configuration.DependencyResolver = resolver;

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            GlobalConfiguration.Configuration.Formatters.Remove(GlobalConfiguration.Configuration.Formatters.XmlFormatter);
        }