Question: How do I avoid passing a service as a parameter in the constructor? If a declare it as an instance, I get a null value. Im using Vaadin14 with Spring Boot and Java v11

```
public interface AccountRoleRepository extends JpaRepository<AccountRole, Long> {
}

@Service
public class AccountRoleRepositoryService {

    @Autowired
    private AccountRoleRepository repository;

    public List<AccountRole> findAll() {
        return repository.findAll();
    }}

@PageTitle("User Access")
@Route(value = "user-access", layout = MainLayout.class)
public class UserAccessView extends Div {

//    @Autowired
//    private AccountRoleRepositoryService accountRoleRepositoryService;  

public UserAccessView(AccountRoleRepositoryService accountRoleRepositoryService) {
    for(AccountRole ar : accountRoleRepositoryService.findAll()){
        System.out.println("role: "+ar.getRole());
    }
}}

```

Answer: 
You should not instantiate @Route classes manually. There's technically nothing preventing you from doing that, but it's almost certainly going to make your code more difficult to understand, and as you have noticed, you can't use Spring dependency injection.
The difference between constructor-injection and field-injection is that with field-injection, the injected component is NOT available (==> null) **during the constructor**, it will be available directly after the constructor, for example in a method annotated with `@PostConstruct` or at any later stage **as long as the constructor has finished**.

```
// example of Vaadin View class using field injection

@PageTitle("User Access")
@Route(value = "user-access", layout = MainLayout.class)
public class UserAccessView extends Div {

@Autowired
private AccountRoleRepositoryService accountRoleRepositoryService;  

public UserAccessView() {
    // accountRoleRepositoryService is null at this point
}}

@PostConstruct
public void methodThatRunsAfterConstructorCompleted() {
    for(AccountRole ar : accountRoleRepositoryService.findAll()){
        System.out.println("role: "+ar.getRole());
    }
}

```

HOWEVER:  

It sounds to me like you ask this because you want to instantiate your UserAccessView Class yourself (-> `new UserAccessView()`). I don't know why you want that, but be aware that ANY injection will not work in this case. Even field injection like above. Injection using `@Autowired` or `@Inject` ONLY work when the class gets instantiated automatically by the underlying framework -> spring components, vaadin views, ..

In my opinion, there is no real upside to using field-injection over constructor-injection. Because usually you want the injected component to be available during the constructor.