injectable

Jersey 2.x Custom Injection annotation NULL

徘徊边缘 提交于 2019-12-12 00:18:51
问题 I'm following the 22.1. Implementing Custom Injection Provider paragraph https://jersey.java.net/documentation/latest/user-guide.html#deployment I defined my classes as below: public class PrincipalConfig extends ResourceConfig { public PrincipalConfig() { packages("com.vex.klopotest.secured,com.klopotek.klas.auth.injection"); register(new MyBinder()); } } Where MyBinder is : Public class MyBinder extends AbstractBinder implements Factory<KasPrincipal> { @Override protected void configure() {

ViewHelper newable/injectable dilemma

南楼画角 提交于 2019-12-10 17:28:37
问题 I'm trying to design an application following Misko Heverys insights. It's an interesting experiment and a challenge. Currently I'm struggling with my ViewHelper implementation. The ViewHelper decouples the model from the view. In my implementation it wraps the model and provides the API for the view to use. I'm using PHP, but I hope the implementation is readable for everyone: class PostViewHelper { private $postModel; public function __construct(PostModel $postModel) { $this->postModel =

How to make Angular2 Service singleton?

心已入冬 提交于 2019-12-10 12:59:17
问题 I'm trying to implement an auth guard in my app. ie; Only authenticated users can access certain routes of my app. I'm following the tut given here. Once the user is logged in I change a boolean value in my AuthService to true to indicate that the use has logged in. Which needs to be retained through out the life of app. Given below the source code: auth-guard.service.ts import { Injectable } from '@angular/core'; import { CanActivate, Router, ActivatedRouteSnapshot, RouterStateSnapshot }

What is the difference between @Inject and @Injectable in Angular 2 typescript

╄→гoц情女王★ 提交于 2019-11-30 13:06:16
I don't understand When to use @Inject and when to use @Injectable ? import {Component, Inject, provide} from '@angular/core'; import {Hamburger} from '../services/hamburger'; export class App { bunType: string; constructor(@Inject(Hamburger) h) { this.bunType = h.bun.type; } } And.. import {Injectable} from '@angular/core'; import {Bun} from './bun'; @Injectable() export class Hamburger { constructor(public bun: Bun) { } } The @Injectable decorator aims to actually set some metadata about which dependencies to inject into the constructor of the associated class. It's a class decorator that

Dependency injection when the class created also needs runtime values?

喜你入骨 提交于 2019-11-30 09:53:23
Assume you divide up your systems in Value objects and Services objects (as suggested in "Growing Object-Oriented Software, Guided by Tests". Misko Hevery calls these "newables" and "injectables". What happens when one of your value objects suddenly needs to access a service to implement it's methods? Let's say you have a nice simple Value object. It's immutable, holds a few bits of information and that's about it. Let's say we use it something like this: CreditCard card = new CreditCard("4111-1111-1111-1111", "07/10"); if (card.isValid()) { // do stuff } else { // don't do stuff } So far so

What is the difference between @Inject and @Injectable in Angular 2 typescript

▼魔方 西西 提交于 2019-11-29 18:45:29
问题 I don't understand When to use @Inject and when to use @Injectable ? import {Component, Inject, provide} from '@angular/core'; import {Hamburger} from '../services/hamburger'; export class App { bunType: string; constructor(@Inject(Hamburger) h) { this.bunType = h.bun.type; } } And.. import {Injectable} from '@angular/core'; import {Bun} from './bun'; @Injectable() export class Hamburger { constructor(public bun: Bun) { } } 回答1: The @Injectable decorator aims to actually set some metadata