Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency injection and inheritance #703

Open
cluka opened this issue Jan 25, 2017 · 2 comments
Open

Dependency injection and inheritance #703

cluka opened this issue Jan 25, 2017 · 2 comments
Labels

Comments

@cluka
Copy link

cluka commented Jan 25, 2017

I'm submitting a bug report

  • Library Version:
    1.0.7

Please tell us about your environment:

  • Operating System:
    Windows 2016 Server

  • Node Version:
    6.9.4

  • NPM Version:
    4.1.1
  • JSPM OR Webpack AND Version
    webpack 2.1.0-beta.27
  • Browser:
    all

  • Language:
    TypeScript 2.1.5

Current behavior:
I don't know if this is a bug or me not doing it right.
Let's say I have this scenarion:

export abstract class ViewModelBase{
    model:any;
    constructor(protected service: any){}
    abstract save();
}

import {DataService1} from './dataService1';
@inject(DataService1)
export class ConcreteViewModel1 extends ViewModelBase{
    constructor(dataService: Dataservice1){
        super(dataService);
    }

    save(){
        this.service.saveData(this.model);
    }
}

import {DataService2} from './dataService2';
@inject(DataService2)
export class ConcreteViewModel2 extends ViewModelBase{
    constructor(dataService: Dataservice2){
        super(dataService);
    }

    save(){
        this.service.saveData(this.model);
    }
}

Now if I do this:

  1. Open a composite which view-model is ConcreteViewModel1. it will instantiate the correct view-model ConcreteViewModel1 and inject the correct dependent service DataService1.
  2. Call view-model save() it will call the correct one.
    then..
  3. Open a composite which view-model is ConcreteViewmodel2. It will again instantiate it correctly.
  4. Call view-model save(), it will call the ConcreteViewmodel2.save().
    But..
  5. I again open a composite which view-model is ConcreteViewModel1 and then
  6. Call view-model save() it will throw exception because in the background it's service property is of type DataService2 and it should be DataService1

Expected/desired behavior:

I expect that the injected service is the correct one.

  • What is the expected behavior?
    I expect that the injected service is the correct one.

  • What is the motivation / use case for changing the behavior?
    To abstract common stuff in a base class, and override the one's that changes in derived classes.

@StrahilKazlachev
Copy link
Contributor

Which version of aurelia-dependency-injection? If it's prior to 1.3.0 could you try with it?

@cluka
Copy link
Author

cluka commented Jan 25, 2017

I don't know which version. I don't have it in packages.json as a separate library and I'm on aurelia-framework v.1.0.7., the one that came with the skeleton: typescript-webpack-skeleton.
How to upgrade it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants