= 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)     // <.>
  TreeNode<T> treeNode(T root)     // <.>
}
----

<.> xref:#getOrCreate_Class[getOrCreate(Class)]
+
--
Gets or creates an instance of _requiredType_ , with injection points resolved and any life-cycle callback processed.
--
<.> xref:#get_Class[get(Class)]
+
--
Gets a _Spring_ managed bean of _requiredType_ .
--
<.> 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, initialized with given _bookmark_ (if any) then resolves any injection points and calls post-construct (if any).
--
<.> xref:#viewModel_Class[viewModel(Class)]
+
--
Creates a new ViewModel instance, with injection points resolved, post-construct called and defaults applied.
--
<.> xref:#viewModel_T[viewModel(T)]
+
--
Resolves injection points for and calls post-construct on given view-model instance.
--
<.> xref:#create_Class[create(Class)]
+
--
Creates a new instance of the specified class, with injection points resolved, post-construct called and defaults applied.
--
<.> xref:#treeNode_T[treeNode(T)]
+
--
In support of built-in tree semantics, as inferred from _PropertyLayout#navigableSubtree()_ or _CollectionLayout#navigableSubtree()_ annotations.
--

== Members

[#getOrCreate_Class]
=== getOrCreate(Class)

Gets or creates an instance of _requiredType_ , with injection points resolved and any life-cycle callback processed.

Maps onto one of the specialized factory methods _#get(Class)_ or _#create(Class)_ based on the type's meta-data.

[#get_Class]
=== get(Class)

Gets a _Spring_ managed bean of _requiredType_ .

[#detachedEntity_Class]
=== detachedEntity(Class)

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

The entity will not yet be persisted, in other words: its not yet known to the persistence layer.

[#detachedEntity_T]
=== detachedEntity(T)

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

The entity will not yet be persisted, in other words: its not yet known to the persistence layer.

[#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, initialized with given _bookmark_ (if any) then resolves any injection points and calls post-construct (if any).

[#viewModel_Class]
=== viewModel(Class)

Creates a new ViewModel instance, with injection points resolved, post-construct called and defaults applied.

[#viewModel_T]
=== viewModel(T)

Resolves injection points for and calls post-construct on given view-model instance.

[#create_Class]
=== create(Class)

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

[#treeNode_T]
=== treeNode(T)

In support of built-in tree semantics, as inferred from _PropertyLayout#navigableSubtree()_ or _CollectionLayout#navigableSubtree()_ annotations.

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

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