public static void Activate() { var ninject = CreateKernel(); var locator = new NinjectServiceLocator(ninject); ServiceLocator.SetLocatorProvider(() => locator); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); // Init Ninject var ninjectBootstrapper = new Ninject.NinjectBootstrapper(); ninjectBootstrapper.LoadModules(); // Use SL pattern to load Main Window / Open a different window var serviceLocator = new NinjectServiceLocator(ninjectBootstrapper.Kernel); // Load up Main Window // As you can see, this method still required to pass the Dependencies of the Windows (all the rest will be resolved). // Since a "new" requires the parameters to be passed... //var mainWindow = new WPF.IOC.MainWindow(serviceLocator.GetInstance<IMainService>()); //mainWindow.Show(); // Using this method, we also resolve our Windows (and UserControls) using an IOC-Container var mainWindow2 = serviceLocator.GetInstance <MainWindow>(); mainWindow2.Show(); // The problem with both solutions is that they do not enable design time data on an easy way. // Design time data will be possible, but less easy than with using ViewModels }
public static void Initialize() { var kernel = new StandardKernel(); kernel.Load(Assembly.GetExecutingAssembly()); var locator = new NinjectServiceLocator(kernel); ServiceLocator.SetLocatorProvider(() => locator); }
public App() { IKernel kernel = new StandardKernel(new DependencyInjection()); NinjectServiceLocator locator = new NinjectServiceLocator(kernel); ServiceLocator.SetLocatorProvider(() => locator); }
/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IKernel kernel) { kernel.Load <CompositionModule>(); var locator = new NinjectServiceLocator(kernel); ServiceLocator.SetLocatorProvider(() => locator); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); IKernel kernel = new StandardKernel(); // Repos kernel.Bind <IClientRepository>().To <InMemoryClientRepository>(); kernel.Bind <ITokenRepository>().To <ShamTokenRepo>(); // Services kernel.Bind <IClientService>().To <ClientService>(); kernel.Bind <ITokenService>().To <TokenService>(); kernel.Bind <IResourceOwnerService>().To <ResourceOwnerService>(); kernel.Bind <IAuthorizationGrantService>().To <AuthorizationGrantService>(); kernel.Bind <IServiceFactory>().To <ServiceFactory>(); //Providers kernel.Bind <IResourceProvider>().To <ResourceProvider>(); // Resource Endpoint Processors //TODO: Build Mac Processor kernel.Bind <ContextProcessor <IResourceContext> >().To <BearerProcessor>(); NinjectServiceLocator adapter = new NinjectServiceLocator(kernel); ServiceLocator.SetLocatorProvider(() => adapter); }
private void SetupDependencyContainer() { var kernel = new Ninject.StandardKernel(); var serviceLocator = new NinjectServiceLocator(kernel); ServiceLocator.SetLocatorProvider(() => serviceLocator); kernel.Bind <Action <string> >().ToMethod(c => this.SetMessage); }
protected override void OnStart(string[] args) { var locator = new NinjectServiceLocator(MessengerWindowsService.GetBindingsConfiguration()); ServiceLocator.SetLocatorProvider(() => locator); this.messenger = new MessageService(); this.messenger.Start(); }
private static IKernel CreateKernel() { var kernel = new StandardKernel(new RobotNinjaModule()); var csl = new NinjectServiceLocator(kernel); kernel.Bind <IServiceLocator>().ToConstant(csl); LoadPluginAssemblies(kernel, kernel.Get <IConfig>()); return(kernel); }
protected override void InitializeServiceLocator() { kernel = new StandardKernel(); kernel.Bind <IProxyFactory>().To <ProxyFactory>(); kernel.Bind <IInvoiceTotalCalculator>().To <SumAndTaxTotalCalculator>(); kernel.Bind <IInvoice>().To <Invoice>().InTransientScope(); IServiceLocator sl = new NinjectServiceLocator(kernel); ServiceLocator.SetLocatorProvider(() => sl); kernel.Bind <IServiceLocator>().ToConstant(sl); }
public void I_d_like_to_have_bindings_loaded_correctly() { //given StandardKernel kernel = new StandardKernel(); //when NinjectServiceLocator locator = new NinjectServiceLocator(kernel); //then Assert.IsNotNull(locator); }
/// <summary> /// Creates the kernel that will manage your application. /// </summary> /// <returns>The created kernel.</returns> private static IKernel CreateKernel() { var kernel = new StandardKernel(); kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel); kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>(); var ninjectServiceLocator = new NinjectServiceLocator(kernel); ServiceLocator.SetLocatorProvider(() => ninjectServiceLocator); RegisterServices(kernel); return kernel; }
protected void Application_Start(object sender, EventArgs e) { var kernel = new StandardKernel(); kernel.Bind<HttpContextBase>().ToConstant(new HttpContextWrapper(this.Context)); kernel.Bind<IJobsRepository>().To<JobsRepository>(); kernel.Bind<IEntityContextResolver>().To<EntityContextResolver>(); var locator = new NinjectServiceLocator(kernel); ServiceLocator.SetLocatorProvider(() => locator); }
/// <summary> /// Создания ядра. /// </summary> /// <returns>Созданное ядро.</returns> private static IKernel CreateKernel() { var kernel = new StandardKernel(); RegisterServices(kernel); InitializeData(kernel); var locator = new NinjectServiceLocator(kernel); ServiceLocator.SetLocatorProvider(() => locator); Kernel = kernel; return(kernel); }
/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IKernel kernel) { var locator = new NinjectServiceLocator(kernel); kernel.Bind(typeof(IRepository<>)).To(typeof(NHibernateRepository<>)); kernel.Bind<IServiceLocator>().ToConstant(locator).InSingletonScope(); kernel.Bind<ISessionFactory>().ToConstant(NHFluentConfiguration.SessionFactory).InSingletonScope(); kernel.Bind<IQueryFactory>().To<QueryFactory>(); kernel.Bind<IPagedPostSearch>().To<PagedPostSearch>(); kernel.Bind<IFindPost>().To<FindPost>(); kernel.Bind<IFindPostBySlug>().To<FindPostBySlug>(); kernel.Bind<ILastPosts>().To<LastPosts>(); kernel.Bind<IAdvancedPostSearch>().To<AdvancedPostSearch>(); }
/// - uNhAddIns.Adapters.CommonTests.EnhancedBytecodeProvider.IDelimiter /// Implementation: uNhAddIns.Adapters.CommonTests.EnhancedBytecodeProvider.ParenDelimiter /// /// - uNhAddIns.Adapters.CommonTests.EnhancedBytecodeProvider.InjectableStringUserType protected override void InitializeServiceLocator() { var kernel = new StandardKernel(); kernel.Bind <IProxyFactory>() .To <ProxyFactory>(); kernel.Bind <IDelimiter>() .To <ParenDelimiter>(); kernel.Bind <InjectableStringUserType>() .ToSelf(); IServiceLocator sl = new NinjectServiceLocator(kernel); ServiceLocator.SetLocatorProvider(() => sl); }
public override void Load() { var locator = new NinjectServiceLocator(Kernel); ServiceLocator.SetLocatorProvider(() => locator); Bind<IServiceLocator>().ToConstant(locator).InSingletonScope(); Bind<IDocumentStore>().ToConstant(new DocumentStore { ConnectionStringName = "RavenDB" }.Initialize()) .InSingletonScope(); Bind<IDocumentSession>() .ToMethod(ctx => ServiceLocator.Current.GetInstance<IDocumentStore>().OpenSession()) .InRequestScope(); }
public override void Load() { var locator = new NinjectServiceLocator(Kernel); ServiceLocator.SetLocatorProvider(() => locator); Bind <IServiceLocator>().ToConstant(locator).InSingletonScope(); Bind <IDocumentStore>().ToConstant(new DocumentStore { ConnectionStringName = "RavenDB" }.Initialize()) .InSingletonScope(); Bind <IDocumentSession>() .ToMethod(ctx => ServiceLocator.Current.GetInstance <IDocumentStore>().OpenSession()) .InRequestScope(); }
private static IMediator BuildMediator() { var kernel = new StandardKernel(); kernel.Components.Add<IBindingResolver, ContravariantBindingResolver>(); kernel.Bind(scan => scan.FromAssemblyContaining<IMediator>().SelectAllClasses().BindDefaultInterface()); kernel.Bind(scan => scan.FromAssemblyContaining<Ping>().SelectAllClasses().BindAllInterfaces()); kernel.Bind<TextWriter>().ToConstant(Console.Out); var serviceLocator = new NinjectServiceLocator(kernel); var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator); kernel.Bind<ServiceLocatorProvider>().ToConstant(serviceLocatorProvider); var handlers = kernel.GetAll<INotificationHandler<Pinged>>(); var mediator = serviceLocator.GetInstance<IMediator>(); return mediator; }
private static IMediator BuildMediator() { var kernel = new StandardKernel(); kernel.Components.Add <IBindingResolver, ContravariantBindingResolver>(); kernel.Bind(scan => scan.FromAssemblyContaining <IMediator>().SelectAllClasses().BindDefaultInterface()); kernel.Bind(scan => scan.FromAssemblyContaining <Ping>().SelectAllClasses().BindAllInterfaces()); kernel.Bind <TextWriter>().ToConstant(Console.Out); var serviceLocator = new NinjectServiceLocator(kernel); var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator); kernel.Bind <ServiceLocatorProvider>().ToConstant(serviceLocatorProvider); var handlers = kernel.GetAll <INotificationHandler <Pinged> >(); var mediator = serviceLocator.GetInstance <IMediator>(); return(mediator); }
public void GetService_WithServiceTypeAndKernel_DelegatesToKernel() { // arrange Func<IEnumerable<object>> returnFunc = () => new[] { new TestService() }; var request = new Mock<IRequest>(); var kernel = new Mock<IKernel>(); kernel.Setup( k => k.CreateRequest(typeof(ITestService), It.IsAny<Func<IBindingMetadata, bool>>(), It.IsAny<IEnumerable<IParameter>>(), It.IsAny<bool>())).Returns(request.Object); kernel.Setup(k => k.Resolve(It.IsAny<IRequest>())).Returns(returnFunc); var serviceLocator = new NinjectServiceLocator(kernel.Object); // act var service = serviceLocator.GetService(typeof(ITestService)); // assert Assert.IsNotNull(service); Assert.AreEqual(typeof(TestService), service.GetType()); }
public void GetService_WithServiceTypeAndKernel_DelegatesToKernel() { // arrange Func <IEnumerable <object> > returnFunc = () => new[] { new TestService() }; var request = new Mock <IRequest>(); var kernel = new Mock <IKernel>(); kernel.Setup( k => k.CreateRequest(typeof(ITestService), It.IsAny <Func <IBindingMetadata, bool> >(), It.IsAny <IEnumerable <IParameter> >(), It.IsAny <bool>())).Returns(request.Object); kernel.Setup(k => k.Resolve(It.IsAny <IRequest>())).Returns(returnFunc); var serviceLocator = new NinjectServiceLocator(kernel.Object); // act var service = serviceLocator.GetService(typeof(ITestService)); // assert Assert.IsNotNull(service); Assert.AreEqual(typeof(TestService), service.GetType()); }
/// <summary> /// Initializes a new instance of the ViewModelLocator class. /// </summary> public ViewModelLocator() { // Different Dependencies are Injected upon design time. if (ViewModelBase.IsInDesignModeStatic) { // Create an instance of NinjectBootstrapper _ninjectBootstrapper = new DesignTimeNinjectBootstrapper(); } else { // Create an instance of NinjectBootstrapper _ninjectBootstrapper = new NinjectBootstrapper(); } // Load the neccesary Modules. _ninjectBootstrapper.LoadModules(); // Set the Ninject Kernel as the ServiceLocatorProvider to make it Resolve our ViewModels (and their dependencies) var serviceLocator = new NinjectServiceLocator(_ninjectBootstrapper.Kernel); ServiceLocator.SetLocatorProvider(() => serviceLocator); }
public RConDevServerApplication() { // create the server instance var serverInstance = new ServerInstance(Settings.Default.ListenOnPort, Settings.Default.MaxSessions); var viewModel = new ServerFormViewModel(serverInstance); var connectionString = ConfigurationManager.ConnectionStrings["Default"]; var connection = new SQLiteConnection(connectionString.ConnectionString); var kernel = new StandardKernel(); IServiceLocator serviceLocator = new NinjectServiceLocator(kernel); serviceLocator.RegisterService(typeof(IDbConnection), connection); // read all available protocols IList<IRconProtocol> protocols = new ProtocolLoader().LoadProtocols("protocols", serviceLocator.Clone() as IServiceLocator); viewModel.AvailableProtocols = protocols; var serverForm = new ServerForm { DataContext = viewModel }; this.MainForm = serverForm; }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); IKernel ninject = new StandardKernel(); var locator = new NinjectServiceLocator(ninject); ServiceLocator.SetLocatorProvider(() => locator); var kernel = ServiceLocator.Current.GetInstance <IKernel>(); kernel.Bind <IEventAggregator>().To <EventAggregator>().InSingletonScope(); kernel.Bind <IMessageBoxService>().To <FancyMessageBoxService>(); kernel.Bind <IIViewProvider>().To <TabbedViewProvider>(); kernel.Bind <IAsyncService>().To <AsyncService>(); kernel.Bind <IDataService <Person> >().To <PeopleDataService>(); kernel.Bind <IDataService <Person> >().To <PeopleDataService2>(); kernel.Bind <IDataService <Company> >().To <CompanyDataService>(); //Application.Run(kernel.Get<Shell>()); Application.Run(ServiceLocator.Current.GetInstance <Shell>()); }
/// <summary> /// Starts the application /// </summary> public static void Start() { var locator = new NinjectServiceLocator(Ninject.Kernel); ServiceLocator.SetLocatorProvider(() => locator); }
private void SetupDependencyContainer() { var kernel = new Ninject.StandardKernel(); var serviceLocator = new NinjectServiceLocator(kernel); ServiceLocator.SetLocatorProvider(() => serviceLocator); kernel.Bind<Action<string>>().ToMethod(c => this.SetMessage); }
public void GivenIHaveANinjectServiceLocator() { IServiceLocator serviceLocator = new NinjectServiceLocator(); UseThisServiceLocator(serviceLocator); }
/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IKernel kernel) { kernel.Components.Add<IBindingResolver, ContravariantBindingResolver>(); kernel.Bind(scan => scan.FromAssemblyContaining<IMediator>().SelectAllClasses().BindDefaultInterface()); kernel.Bind(scan => scan.FromAssemblyContaining<MoviesQuery>().SelectAllClasses().BindAllInterfaces()); var serviceLocator = new NinjectServiceLocator(kernel); var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator); kernel.Bind<ServiceLocatorProvider>().ToConstant(serviceLocatorProvider); }
static void Main(string[] args) { XmlConfigurator.Configure(); var serviceName = ConfigurationManager.AppSettings["ServiceName"].IfNullOrEmpty("Concentrator Service Host"); AppDomain.CurrentDomain.AssemblyResolve += (sender, arguments) => { var pluginDirectory = ConfigurationManager.AppSettings["PluginPath"]; if (!Directory.Exists(pluginDirectory)) { throw new IOException(String.Format("'{0}' does not exist.", pluginDirectory)); } var assemblyName = new AssemblyName(arguments.Name); var fullName = Path.Combine(pluginDirectory, assemblyName.Name + ".dll"); if (!File.Exists(fullName)) { throw new IOException(String.Format("'{0}' does not exist.", fullName)); } return(Assembly.LoadFile(fullName)); }; #if DEBUG IKernel kernel = new ConcentratorKernel(new ManagementServiceModule(), new ContextThreadScopeModule(), new ThreadScopeUnitOfWorkModule(), new UnsecuredRepositoryModule(), new ServiceModule()); var locator = new NinjectServiceLocator(kernel); ServiceLocator.SetLocatorProvider(() => locator); if (args.Length > 0) { ServiceLayer.Start(args[0].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray().Select(c => int.Parse(c)).ToArray()); } else { ServiceLayer.Start(); } Console.ReadLine(); ServiceLayer.Stop(); #else RunConfiguration cfg = RunnerConfigurator.New(x => { IKernel kernel = new ConcentratorKernel(new ManagementServiceModule(), new ContextThreadScopeModule(), new ThreadScopeUnitOfWorkModule(), new UnsecuredRepositoryModule(), new ServiceModule()); var locator = new NinjectServiceLocator(kernel); ServiceLocator.SetLocatorProvider(() => locator); x.ConfigureService <ServiceLayer>(s => { s.Named("tc"); s.HowToBuildService(name => ServiceLayer.Instance); s.WhenStarted(tc => ServiceLayer.Start()); s.WhenStopped(tc => ServiceLayer.Stop()); }); x.SetDescription("Concentrator Host Process for running plugins"); x.SetDisplayName(serviceName); //staging x.SetServiceName(serviceName); //staging x.RunAsLocalSystem(); // } }); Runner.Host(cfg, args); #endif }
private static void SetCommonServiceLocator(IKernel kernel) { var locator = new NinjectServiceLocator(kernel); ServiceLocator.SetLocatorProvider(() => locator); }
private void RegisterServiceLocator(IKernel kernel) { var ninject = new NinjectServiceLocator(kernel); ServiceLocator.SetLocatorProvider(() => ninject); }
public MainWindow() { InitializeComponent(); tabNavigationService = NinjectServiceLocator.GetStuff <ITabNavigationService>(); // projectDataService = NinjectServiceLocator.GetStuff<IProjectDataService>(); }
private void SetServiceLocator() { var locator = new NinjectServiceLocator(_ninjectKernel); ServiceLocator.SetLocatorProvider(() => locator); }
private static void RegisterServiceLocator(IKernel kernel) { var ninjectServiceLocator = new NinjectServiceLocator(kernel); ServiceLocator.SetLocatorProvider(() => ninjectServiceLocator); }