Use class object check without injection in Aurelia

I came across one issue related to injection (s) in Aurelia. I was wondering how to implement Validation, EventAggregator and Router without injection.

Below you can find an example that can give you a clear picture of the implementation and where I am stuck.

The class profile interacts with the view, and the AddressList object is created in the profile class, and this object (AddressList) interacts with the view.

For instance:

@inject(EventAggregator, Validation, Router)
export class Profile{
      addressList: Array<AddressList> = [];
      eventAgg:any;
      _validation:any;
      _router:any;
      constructor(EventAggregator, Validation, Router )
                  {
                   this.eventAgg = EventAggregator;
                   this._validation = Validation;
                   this._router = Router;
                   this.addressList.push(new AddressList());
                  }
}

export class AddressList{
      street1:string = "street1";
      street2:string = "street2";
constructor(){
}

Now I want to implement addressList property checks without passing validation in the AddressList constructor

I do not want it

this.addressList.push(new AddressList(Valdiation));

Because it will create problems when I want to pass arguments in the AddressList constructor.

, , , .

,


/

, . , AddressList undefined.

import { Factory } from 'aurelia-framework';
import { ObserverLocator } from 'aurelia-framework';
import { EventAggregator } from 'aurelia-event-aggregator';
import { Validation, ensure } from 'aurelia-validation';

@inject(EventAggregator, Validation, Factory.of(AddressList))
export class Profile{
   addressList: Array<AddressList> = [];
      eventAgg:any;
      _validation:any;
      _router:any;
      constructor(EventAggregator, Validation, AddressList)
                  {
                   this.eventAgg = EventAggregator;
                   this._validation = Validation;
                   this.addressList.push(AddressList(["street1","street2"]));
                  }
 }

@inject(Validation)
export class AddressList{
      street1:string = "street1";
      street2:string = "street2";
      constructor(Validation, args){
         this.street1=args[0];
         this.street2=args[1];
     }
}

AddressList
function() {
        for (var _len = arguments.length, rest = Array(_len), _key = 0; _key < _len; _key++) {
        rest[_key] = arguments[_key];
        }

    return container.invoke(_this2._…
AddressList ()

Error snapshot

- Container.prototype._createInvocationHandler:

 if (fn.inject === undefined)

fn undefined.

, , , .

+2
2

, Aurelia Factory resolver:

import { Factory } from 'aurelia-framework';

@inject(Factory.of(AddressList))
export class Profile {

    addressList: Array<AddressList> = [];

    constructor(AddressList) {
        this.addressList.push(
            AddressList(['123 Elm St.', 'Apt B.'])
        );
    }
}

@inject(Validation)
export class AddressList {

    street1;
    street2;

    constructor(Validation, addressList: string[]) {
        this._validation = Validation;
        this.street1 = addressList[0];
        this.street2 = addressList[1];
    }
}
0

, , typescript, , inject aurelia-framework.

:

private static inject = [EventAggregator, Validation, Factory.of(AddressList)]

typescript, , .

0

All Articles