Skip to content

Conversation

@ffujita
Copy link
Owner

@ffujita ffujita commented Feb 1, 2019

No description provided.

}

@Autowired
MessageDao messageDao;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Springチームはコンストラクタインジェクションを推奨しています。
https://docs.spring.io/spring/docs/5.1.4.RELEASE/spring-framework-reference/core.html#beans-constructor-vs-setter-injection

私もコンストラクタインジェクションの方が好き。
理由は次の通り。

  • フィールドを final にできる
  • コンストラクタの引数チェックで null でないことを保証できる
  • コンストラクタで依存クラスを設定できるので、Spring管理下ではなく単なるクラスとしてテストが書ける

コード例:

final MessageDao messageDao;

public MessageApplication(MessageDao messageDao) {
    this.messageDao = Objects.requireNonNull(messageDao);
}

@@ -0,0 +1,5 @@
SELECT
id,
content

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テーブルが持つカラムをすべて取得する場合は expand が使えます。
https://doma.readthedocs.io/en/stable/sql/#expand

使え!というわけではないけれど、便利です。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants