=== Nature of Service

:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
:page-partial:


The xref:refguide:applib:index/annotation/DomainService.adoc#nature[nature()] element indicates the intent of the actions defined within the domain service:

* `VIEW`
+
The default; the service's actions appear on menu bars, can be contributed, appear in the REST API

* `REST`
+
The service's actions are intended only to be listed in the REST API exposed by the xref:vro:ROOT:about.adoc[RestfulObjects viewer].

The actual class name of the domain service is only rendered for the `VIEW` natures.

For example:

[source,java]
----
@DomainService
@RequiredArgsConstructor(onConstructor_ = {@Inject} )
public class Loans {                                    // <.>

    private final LoanRepository loanRepository;        // <.>

    @Action(semantics=SemanticsOf.SAFE)
    public List<Loan> findOverdueLoans() {
        // ...
    }
}
----
<.> name is intended to be rendered in the UI
<.> it's common for domain-layer domain services to be injected into presentation layer services.


For services that do not need to appear in the UI and do not need to be invoked using xref:refguide:applib:index/services/wrapper/WrapperFactory.adoc[WrapperFactory] (in other words, do not need to be part of the metamodel), you can declare the service using Spring's `@Service`, `@Repository` or `@Component` annotations.

For example:

[source,java]
----
@Repository
public class LoanRepository {
    public List<Loan> findLoansFor(Borrower borrower) {
        // ...
    }
}
----


