# Event aggregator publish event from a value converter

**URL:** <https://discourse.aurelia.io/t/event-aggregator-publish-event-from-a-value-converter/6474>\
**Category:** Help Requests\
**Created:** [July 9, 2025, 9:12am UTC](https://discourse.aurelia.io/t/event-aggregator-publish-event-from-a-value-converter/6474 "2025-07-09T09:12:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vladyn](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/vladyn/32/2473_2.png) [@vladyn](https://discourse.aurelia.io/u/vladyn)\
**Post date:** [July 9, 2025, 9:12am UTC](https://discourse.aurelia.io/t/event-aggregator-publish-event-from-a-value-converter/6474/1 "2025-07-09T09:12:42Z")

</div>

Hello everybody,  
I’m trying to do something (which is probably an anti-pattern),  
but I need an event published from a values converter.  
I have

```auto
TypeError: can't access property "publish", this.eventAggregator is undefined

```

which is most definitely a circular dependency. My question is:  
how can I ‘signal’ from a value converter, which is in massive use in the App without have such issues.  
I had a previous version where I was trying to do this via service, but again I had these undefined, properties, caused from a Circular dependency.  
My code:

```auto
import { inject } from 'aurelia-framework';
import { EventAggregator } from 'aurelia-event-aggregator';
import { thousandsSeparator } from '../utils/thousands-separator';
import { CurrencyService } from '../services/currency-service';
import { currencyModes } from '../enums/currency-modes';
import { WrongCurrencyEvent } from '../services/event/wrong-currency-event';

@inject(EventAggregator, CurrencyService)
export class SumFormatValueConverter {
  constructor(eventAggregator, currencyService = new CurrencyService()) {
    this.currencyService = currencyService;
    this.eventAggregator = eventAggregator;
  }

  toView(value, ...args) {
    if (value === null || value === undefined) return;
    this.defaultCurrency = this.currencyService.getDefaultCurrency(); // EUR
    this.currency = this.currencyService.getCurrency(); // BNG
    this.config = Number(this.currencyService.getConfig()); // 0 EUR (BGN), 1 - EUR, -1 - BGN
    const { euro, lv } = currencyModes;

    const formattedValue = this._normalizeValue(value);
    if (!this._isValidFormattedValue(formattedValue)) {
      return;
    }

    const primaryCurrency = this._formatAmount(formattedValue, 'amount');
    const secondaryCurrency = this._formatAmount(formattedValue, 'amountSecondary');

  _normalizeValue(value) {
    const amountSecondary = value?.amountSecondary ?? 0;
    const currency = this.defaultCurrency;

    switch (true) {
      case typeof value === 'number':
      case Number.isFinite():
        this.eventAggregator.publish(new WrongCurrencyEvent(`Wrong currency value - ${value}`));
        return { amount: value, currency, amountSecondary };

      case typeof value === 'string' && Number.isFinite(Number(value)):
        this.currencyLogger.logCallStack(`Wrong currency value - ${value}`);
        return { amount: Number(value), currency, amountSecondary };
      case (value?.amount !== 0 && value.amountSecondary === 0) || (value?.amount === 0 && value.amountSecondary !== 0):
        this.eventAggregator.publish(new WrongCurrencyEvent(`Wrong currency value(s) - amount: ${value?.amount}, amountSecondary: ${value?.amountSecondary}`));
        return { amount: value?.amount, currency, amountSecondary }
      default:
        return { amount: value?.amount, currency, amountSecondary };
    }
  }

  _isValidFormattedValue(formattedValue) {
    return (
      ...
    );
  }

  _formatAmount(formattedValue, amount) {
    // code here
  }

  _formatOutput(amount, currency) {
    return ...
}

```

---

<div class="post-metadata">

**Author:** ![bigopon](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/bigopon/32/18_2.png) [@bigopon](https://discourse.aurelia.io/u/bigopon)\
**Post date:** [July 10, 2025, 10:16pm UTC](https://discourse.aurelia.io/t/event-aggregator-publish-event-from-a-value-converter/6474/2 "2025-07-10T22:16:56Z")

</div>

it’s likely you did something like this:

```ts
const { toView } = this.mySumFormatValueConverter;

toView(someValue);

```

The above breaks because `toView` is called without its context, which is the `SumFormatValueConverter` instance.

---

<div class="post-metadata">

**Author:** ![vladyn](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/vladyn/32/2473_2.png) [@vladyn](https://discourse.aurelia.io/u/vladyn)\
**Post date:** [July 11, 2025, 2:17pm UTC](https://discourse.aurelia.io/t/event-aggregator-publish-event-from-a-value-converter/6474/3 "2025-07-11T14:17:20Z")

</div>

Then how should I call it?  
I think in this case, I’m hitting a circular dependency.

---

<div class="post-metadata">

**Author:** ![bigopon](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/bigopon/32/18_2.png) [@bigopon](https://discourse.aurelia.io/u/bigopon)\
**Post date:** [July 13, 2025, 3:02pm UTC](https://discourse.aurelia.io/t/event-aggregator-publish-event-from-a-value-converter/6474/4 "2025-07-13T15:02:30Z")

</div>

Maybe something like thid

```ts
this.mySumFormatValueConverter.toView(value)

```
