The inversify middleware is executed a single time

I utilize Inversify for object binding in the following manner:

container.applyMiddleware(loggerMiddleware);

let module = new ContainerModule((bind: interfaces.Bind) => {
    bind<Logger>(TYPES.Logger).toConstantValue(logger);
    bind<ILoggerFactory>(TYPES.ILoggerFactory).to(WinstonLoggerFactory);

    bind<string>(TYPES.ConnectionString).toConstantValue(cs);
    bind<{}>(TYPES.ConnectionOptions).toConstantValue({});

    bind<ITradeController>(TYPES.ITradeController).to(TradeController);
    bind<ITradeService>(TYPES.ITradeService).to(TradeService).whenInjectedInto(TradeController);
    bind<ITradeRepository>(TYPES.ITradeRepository)
      .to(TradeMongoRepository)
      .whenInjectedInto(TradeService);

    bind<IUserService>(TYPES.IUserService).to(UserService).whenInjectedInto(TradeService);
    bind<IUserRepository>(TYPES.IUserRepository)
      .to(UserMongoRepository)
      .whenInjectedInto(UserService);
  });

container.load(module);

Furthermore, I have defined an Inversify middleware as shown below:

import * as inversify from 'inversify';

function logger(next: inversify.interfaces.Next): inversify.interfaces.Next {
  return (args: inversify.interfaces.NextArgs) => {
    let start = new Date().getTime();
    let result = next(args);
    let end = new Date().getTime();
    console.log(`wooooo  ${end - start}`);
    return result;
  };
}

export default logger;

Upon running the application, only a single message 'wooooo' is displayed.

For instance, if services are invoked using the code snippet below:

const tradeController = container.get<ITradeController>(TYPES.ITradeController);
const result = await tradeController.findByUserId(params.userId);

When the `tradeController` calls `tradeService`, and subsequently the `tradeService` calls `tradeRepository`, each level is expected to log 'wooooo', but only one log entry is recorded. What could be causing this issue?

Answer №1

Inversify's middlewares are executed just once, offering unique functionalities compared to AOP interceptors which is why they are only called once.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What steps do I need to take to execute a browserify-ed application in NodeJS?

I have an interesting challenge on my hands - I need to modify a sizable JavaScript codebase to be compatible with NodeJS. The current code follows the CommonJS style and utilizes a gulp build process involving browserify and deamdify. While I am somewhat ...

The width of the Ion-slide is dynamically determined by the styling

After transitioning my Ionic 2 project to Ionic 3, I encountered issues with ion-slides which are affecting my app's functionality. Upon app loading, specific widths are being defined in the style tags on the slides, disrupting the intended styling. ...

Angular - Dividing Functionality into Multiple Modules

I am currently working with two separate modules that have completely different designs. To integrate these modules, I decided to create a new module called "accounts". However, when I include the line import { AppComponent as Account_AppComponent} from &a ...

Tips for updating Angular HTML with data received from Socket.IO

I am currently working on a socket program that is listening and providing log data. The socket is sending the correct data as I can see it in the console. Below is a snippet of my code: export class RoboLogComponent implements OnInit { dataToShow:any @V ...

Differences Between Data Captured from Form Submissions and Data Obtained Through Ajax

When attempting to incorporate reCAPTCHA into my MVC site, I encountered an issue where it would not validate unless submitted from a form. Here is the current implementation: @using(Html.BeginForm("VerifyCaptcha", "Signup") ) { @ReCaptch ...

Tips for converting text input in a textbox to a Date value

My knowledge of Angular is limited, and we are currently using Angular 10. In our application, there is a textbox where users need to input a date in the format 10202020. This value should then be reformatted as 10/20/2020 and displayed back in the same ...

Struggling with displaying values from an array using getJSON

I've encountered an issue with displaying the results of a $.getJSON call. The code I have retrieves JSON data from a specific page. var loadItems = function() { if (hasNextPage === false) { return false } pageNum = pageNum + 1; var url = baseUr ...

Load a React component in the same spot when clicked

Is there a way to implement a functionality where clicking on different buttons in a panel will display different components in the same location? <AddNotification /> <EditNotification /> <DeleteNotification /> const AdminPanel = () =& ...

Having issues with jQuery not functioning on this specific web page across all browsers. The reason behind this puzzling dilemma remains elusive to me

I am experiencing issues with the functionality of my website. The buttons with + signs are meant to be drop-down toggles, and the mini-tabs below them should work as tabs. Additionally, the sample images at the bottom are not loading properly when clicked ...

The setTimeout function fails to behave as intended when used in conjunction with synchronous ajax

Within my code, I have a function that is being invoked multiple times due to iterating through an array of length n and creating 'Plants' with synchronous ajax calls. These calls involve querying the Google Maps API, so it is crucial to throttle ...

How can I retrieve a Jquery tooltip from a HiddenField?

I am trying to utilize a hidden field in my asp.net calendar to display a message using JQ Tooltip. However, when I attempt to use the value of the HiddenField for the tooltip, I encounter an error. $("#hf_taskID_cal").tooltip($("#hf_taskID_cal").val()); ...

Iterate through the URL parameters and store them in the database

I need to efficiently loop through all my post requests and aggregate them collectively. What is the most effective approach for achieving this? Below is the Form structure along with the data I receive: var Form = new Schema({ title: { type: ...

I am experiencing unexpected results with my Mongoose filter and sort query in Express JS middleware. The output does not match what I am anticipating, and the sorting functionality seems to

This middleware is used for filtering and sorting data. I made some modifications to it, but it's not functioning as expected: const aliasTopMenu = (req, res, next) => { req.query.sort = '-price'; req.query.fields = 'name,price, ...

When utilizing AngularFire with Firebase Firestore Database, users may encounter instances where data duplication occurs on

Currently facing a challenge in my Angular 13.1 Project utilizing @angular/fire 7.4.1 for database management The issue arises consistently across various screens where data from Firestore Database is displayed, particularly on List screens. The lists are ...

"Define a TypeScript function type that can return either an object or a string depending on whether it succeeds or fails

I encountered an issue with a function that either returns a Promise on success or a string on error. async create(createDebtorDto: CreateDebtorDto): Promise<Debtor> { console.log("createDebtorDto", createDebtorDto) try{ const createdD ...

How to retrieve data as an array using a promise in an Express application with React and

After including an array in the return statement, everything seems to be functioning correctly with dispatch and rendering in reducer-items.js. However, there is a discrepancy when I update the data as it does not reflect the changes made. export defa ...

If a span element is present, apply a specific class to the corresponding

I am working with a dynamic list of links retrieved through AJAX. After parsing the links and appending them to a div, I have encountered an issue where some 'a' elements are followed by a 'span' that needs to be considered. Here is th ...

The Kendo Grid is refusing to show up within the popup window

I am new to using Angular 2 and Kendo UI. Currently, I am attempting to include a grid inside my pop-up window. While I have successfully displayed the pop-up, adding the grid has proven challenging. The grid is not appearing as expected ...

empty responseText from GET request using AJAX

I've been working on a chatbox using AJAX and I've encountered an issue where my xhttp.responseText is coming back empty. In firebug, I can see that the GET request is being sent and the correct text is being returned, but for some reason it&apos ...

Displaying Information in Angular Modal Windows

I'm facing an issue while trying to create an edit button for a formGroup that is initially saved. When the user clicks on the adjacent button, a modal should open with editable data. However, I encountered this error and haven't been able to res ...