本文整理汇总了C#中Ninject.StandardKernel类的典型用法代码示例。如果您正苦于以下问题:C# StandardKernel类的具体用法?C# StandardKernel怎么用?C# StandardKernel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StandardKernel类属于Ninject命名空间,在下文中一共展示了StandardKernel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_not_throw_exception_when_loading_multiple_inline_modules
public void Should_not_throw_exception_when_loading_multiple_inline_modules()
{
IKernel kernel = new StandardKernel();
kernel.Bind<IService>().To<ServiceImpl>();
kernel.Bind<IService2>().To<Service2Impl>();
}
示例2: Index
//
// GET: /Management/
public ActionResult Index()
{
IKernel kernel = new StandardKernel(new DataModelCreator());
var users = kernel.Get<IRepository<User>>().GetAll().Where(u => u.Id != WebSecurity.CurrentUserId);
return View(users);
}
示例3: ConnectInfoForm
public ConnectInfoForm()
{
XmlConfigurator.Configure();
var settings = new NinjectSettings()
{
LoadExtensions = false
};
this.mKernel = new StandardKernel(
settings,
new Log4NetModule(),
new ReportServerRepositoryModule());
//this.mKernel.Load<FuncModule>();
this.mLoggerFactory = this.mKernel.Get<ILoggerFactory>();
this.mFileSystem = this.mKernel.Get<IFileSystem>();
this.mLogger = this.mLoggerFactory.GetCurrentClassLogger();
InitializeComponent();
this.LoadSettings();
// Create the DebugForm and hide it if debug is False
this.mDebugForm = new DebugForm();
this.mDebugForm.Show();
if (!this.mDebug)
this.mDebugForm.Hide();
}
示例4: Main
public static void Main (string[] args)
{
var kernel = new StandardKernel();
Container = new Container(kernel);
Configure.With(Container)
.UsingJsonStorage("JsonDB")
.Initialize();
var commandCoordinator = ServiceLocator.Current.GetInstance<ICommandCoordinator>();
var command = new CreatePerson(Guid.NewGuid(), "First", "Person");
var result = commandCoordinator.Handle(command);
if (!result.Success)
{
Console.WriteLine("Handling of command failed");
Console.WriteLine("Exception : {0}\nStack Trace : {1}", result.Exception.Message, result.Exception.StackTrace);
}
var queries = Container.Get<IPersonView>();
var persons = queries.GetAll();
foreach (var person in persons)
{
Console.WriteLine("Person ({0}) - {1} {2}", person.Id, person.FirstName, person.LastName);
}
}
示例5: ShouldBeAbleToGetBusinessServiceFromNinject
public void ShouldBeAbleToGetBusinessServiceFromNinject()
{
BusinessService actual;
var kernel = new StandardKernel(new CoreModule());
actual = kernel.Get<BusinessService>();
Assert.IsNotNull(actual);
}
示例6: GetRestClient
private static IRestClient GetRestClient()
{
IKernel kernel = new StandardKernel();
kernel.Load(Assembly.GetExecutingAssembly());
return kernel.Get<IRestClient>();
}
示例7: RegisterDependencyResolver
private static void RegisterDependencyResolver()
{
var kernel = new StandardKernel();
kernel.Bind<ICalendarService>().To<CalendarService>();
DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
}
示例8: Initialize
private void Initialize()
{
if (_kernel != null) return;
_kernel = new StandardKernel();
_kernel.Bind<Func<Type, NotifyableEntity>>().ToMethod(context => t => context.Kernel.Get(t) as NotifyableEntity);
_kernel.Bind<PhoneApplicationFrame>().ToConstant(new PhoneApplicationFrame());
_kernel.Bind<INavigationService>().To<NavigationService>().InSingletonScope();
_kernel.Bind<IStorage>().To<IsolatedStorage>().InSingletonScope();
_kernel.Bind<ISerializer<byte[]>>().To<BinarySerializer>().InSingletonScope();
_kernel.Bind<IDataContext>().To<DataContext>().InSingletonScope();
_kernel.Bind<IGoogleMapsClient>().To<GoogleMapsClientMock>().InSingletonScope();
_kernel.Bind<IConfigurationContext>().To<ConfigurationContext>().InSingletonScope();
ApplicationContext.Initialize(_kernel);
var place1 = ApplicationContext.Data.AddNewPlace(new Location
{
Latitude = 9.1540930,
Longitude = -1.39166990
});
var place2 = ApplicationContext.Data.AddNewPlace(new Location
{
Latitude = 9.1540930,
Longitude = -1.39166990
});
ApplicationContext.Data.GetRoute(null, null, default(TravelMode), default(RouteMethod), r =>
{
r.Result.ArrivalPlaceId = place1.Id;
r.Result.DeparturePlaceId = place2.Id;
});
ApplicationContext.Data.ToolbarAlignment.Value = HorizontalAlignment.Left;
}
示例9: CreateKernel
/// <summary>
/// Creates the kernel that will manage your application.
/// </summary>
/// <returns>The created kernel.</returns>
protected override IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Bind<IHomeControllerModel>().To<HomeControllerModel>();
kernel.Bind<ILog>().ToMethod(ctx => LogManager.GetLogger("xxx"));
return kernel;
}
示例10: CreateKernel
/// <summary>
/// Creates the kernel that will manage your application.
/// </summary>
/// <returns>The created kernel.</returns>
private static IKernel CreateKernel()
{
var documentStore = new EmbeddableDocumentStore
{
UseEmbeddedHttpServer = true,
DataDirectory = "App_Data",
Configuration =
{
Port = 12345,
},
Conventions =
{
CustomizeJsonSerializer = MvcApplication.SetupSerializer
}
};
documentStore.Initialize();
var manager = new SubscriptionManager(documentStore);
var kernel = new StandardKernel();
kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
kernel.Bind<IDocumentStore>()
.ToMethod(context => documentStore)
.InSingletonScope();
RegisterServices(kernel);
kernel.Bind<SubscriptionManager>().ToMethod(context => manager).InSingletonScope();
return kernel;
}
示例11: Init
public void Init()
{
var container = new StandardKernel();
container.Bind<ISessionRepository>().ToConstant(MoqSessionRepositoryFactory.GetSessionRepositoryMock());
_sessionRepository = container.Get<ISessionRepository>();
_sessionRepository.Clear();
}
示例12: BindingExtensionsTest
public BindingExtensionsTest()
{
this.eventAggregator = new Mock<IEventAggregator>();
this.kernel = new StandardKernel(new NinjectSettings { LoadExtensions = false });
this.kernel.Bind<IEventAggregator>().ToConstant(this.eventAggregator.Object);
}
示例13: Application_Start
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
//Setup Ninject Kernel and wire up services using convention based binding in Ninject 3.0
var kernel = new StandardKernel();
kernel.Bind(x => x
.FromAssembliesMatching("*")
.SelectAllClasses()
.BindDefaultInterface());
//Or bind each class using the following syntax:
//kernel.Bind<IStupidLittleService>().To<StupidLittleService>().InRequestScope();
//Setup DR for MVC Controllers
NinjectDependencyResolver resolver = new NinjectDependencyResolver(kernel);
DependencyResolver.SetResolver(resolver);
//Setup DR for Web API Controllers
NinjectWebApiDependencyResolver webApiDependencyResolver = new NinjectWebApiDependencyResolver(kernel);
GlobalConfiguration.Configuration.DependencyResolver = webApiDependencyResolver;
}
示例14: Main
private static void Main()
{
XmlConfigurator.Configure(new FileInfo("patientOrderService.log4net.xml"));
HostFactory.Run(
c =>
{
c.SetServiceName("SampleSOAPatientOrderService");
c.SetDisplayName("Sample SOA Patient Order Service");
c.SetDescription("A sample SOA service for handling Patient Orders.");
c.RunAsNetworkService();
StandardKernel kernel = new StandardKernel();
PatientOrderServiceRegistry module = new PatientOrderServiceRegistry();
kernel.Load(module);
c.Service<PatientOrderService>(
s =>
{
s.ConstructUsing(builder => kernel.Get<PatientOrderService>());
s.WhenStarted(o => o.Start());
s.WhenStopped(o => o.Stop());
});
});
}
示例15: CreateKernel
private static StandardKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Load(Assembly.GetExecutingAssembly());
RegisterMappings(kernel);
return kernel;
}