= FactoryService
: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.

Collects together methods for instantiating domain objects, also injecting them with any domain services and calling lifecycle methods if defined.

== API

[source,java]
.FactoryService.java
----
interface FactoryService {
  T getOrCreate(Class<T> requiredType)     // <.>
  T get(Class<T> requiredType)     // <.>
  T detachedEntity(Class<T> domainClass)     // <.>
  T detachedEntity(T entity)     // <.>
  T mixin(Class<T> mixinClass, Object mixedIn)     // <.>
  T viewModel(Class<T> viewModelClass, Bookmark bookmark)     // <.>
  T viewModel(Class<T> viewModelClass)     // <.>
  T viewModel(T viewModel)     // <.>
  T create(Class<T> domainClass)     // <.>
}
----

<.> xref:#getOrCreate_Class[getOrCreate(Class)]
+
--
Gets an instance (possibly shared or independent) of the specified type, with injection points resolved and any life-cycle callback processed.
--
<.> xref:#get_Class[get(Class)]
+
--
Gets an instance (possibly shared or independent) of the specified _requiredType_ , with injection points resolved and any life-cycle callback processed.
--
<.> xref:#detachedEntity_Class[detachedEntity(Class)]
+
--
Creates a new detached entity instance, with injection points resolved and defaults applied.
--
<.> xref:#detachedEntity_T[detachedEntity(T)]
+
--
Creates a new detached entity instance, with injection points resolved.
--
<.> xref:#mixin_Class_Object[mixin(Class, Object)]
+
--
Creates a new Mixin instance, with injection points resolved.
--
<.> xref:#viewModel_Class_Bookmark[viewModel(Class, Bookmark)]
+
--
Creates a new ViewModel instance, with injection points resolved, and initialized according to the given _bookmark_
--
<.> xref:#viewModel_Class[viewModel(Class)]
+
--
Creates a new ViewModel instance, with injection points resolved and defaults applied.
--
<.> xref:#viewModel_T[viewModel(T)]
+
--
Resolves injection points for given ViewModel instance.
--
<.> xref:#create_Class[create(Class)]
+
--
Creates a new instance of the specified class, with injection points resolved and defaults applied.
--

== Members

[#getOrCreate_Class]
=== getOrCreate(Class)

Gets an instance (possibly shared or independent) of the specified type, with injection points resolved and any life-cycle callback processed.

[#get_Class]
=== get(Class)

Gets an instance (possibly shared or independent) of the specified _requiredType_ , with injection points resolved and any life-cycle callback processed.

[#detachedEntity_Class]
=== detachedEntity(Class)

Creates a new detached entity instance, with injection points resolved and defaults applied.

The entity will be detacted, in other words not yet persisted.

[#detachedEntity_T]
=== detachedEntity(T)

Creates a new detached entity instance, with injection points resolved.

[#mixin_Class_Object]
=== mixin(Class, Object)

Creates a new Mixin instance, with injection points resolved.

[#viewModel_Class_Bookmark]
=== viewModel(Class, Bookmark)

Creates a new ViewModel instance, with injection points resolved, and initialized according to the given _bookmark_

[#viewModel_Class]
=== viewModel(Class)

Creates a new ViewModel instance, with injection points resolved and defaults applied.

[#viewModel_T]
=== viewModel(T)

Resolves injection points for given ViewModel instance.

[#create_Class]
=== create(Class)

Creates a new instance of the specified class, with injection points resolved and defaults applied.

include::hooks/FactoryService_010-implementation.adoc[]

include::hooks/FactoryService_020-examples-and-usage.adoc[]
