Spring DI with different styles

Spring as a dependency injection (DI) framework allows us to define our application components' dependency tree in three different ways: XML Annotation Java Config I've written a simple app, bookstore, with the three styles and they're available in the following repository. You can take a look and see how each style would look like. It also has a version that uses no Spring beans for comparison. https://github.com/ryu1kn/spring--working-with-beans Different styles have different pros/cons. Spring lets you mix the styles; so you can change it as you go. Here is my observations on each style. XML-based configuration Pros Weak/loose coupling with Spring framework in your app code. Good for keeping the option of removing Spring later Class dependency information is centralised. Fine-grained control on the dependency definition. Changing only the dependency information doesn't require the recompilation of your app code. Cons Unless you have a good IDE

Leverage shell commands to quickly edit text on Visual Studio Code

I really like vi. When I started using Visual Studio Code as my main editor shortly after it hit version 1, one thing I felt missing in Code was the ability to quickly edit text using various commands already available on your shell. For example, let’s say you’re editing a section of text that looks like following.

Contributors:

    - Mike, 3 PRs
    - Elizabeth, 5 PRs
    - Robert, 2 PRs
    - Mary, 10 PRs

If you want to order the contributors by the amount of contributions, in vi, you can utilise shell’s sort command:

  1. Select the list of contributors
  2. Execute a shell command sort -t, -k 2 -n -r on the visual mode

Then you’ll get

Contributors:

    - Mary, 10 PRs
    - Elizabeth, 5 PRs
    - Mike, 3 PRs
    - Robert, 2 PRs

If you want to drop the number of PRs from the list, you can just pipe the sort output to cut command (e.g. sort -t, -k 2 -n -r | cut -d, -f1), because it’s just a shell command!

Contributors:

    - Mary  
    - Elizabeth  
    - Mike  
    - Robert

You can leverage all the powerful commands available on your shell! And, this is exactly what Edit with Shell Command extension offers you on Code; Editing selected text with commands available on your shell.

Here is how it works ⬇️ (Example text is different from the above)

You can also just insert shell commands output at the cursor position instead of modifying text in the editor.

If you often come across situations where you feel, “Ah… it would be a piece of cake if I can use foo command on the shell”, give the extension a try on your Code 👍

Comments

Popular posts from this blog

Use Blogger API from its Java client

Spring DI with different styles

Vim + Syntastic + JSHint