Interface IDataFactory
A data builder which will generate items for a specific type. In many cases it will also take care of auto increasing the id and more.
[PublicApi]
public interface IDataFactory
Remarks
- Added in v15 to replace the previous IDataBuilder
Properties
ContentType
The generated ContentType. This will only be generated once, for better performance.
IContentType ContentType { get; }
Property Value
IdCounter
A counter for the ID in case the data provided doesn't have an ID to use.
Default is 1
int IdCounter { get; }
Property Value
Relationships
TODO:
ILookup<object, IEntity> Relationships { get; }
Property Value
Methods
Create(IDictionary<string, object>, int, Guid, DateTime, DateTime, EntityPartsBuilder)
Create a single entity based on values passed in.
IEntity Create(IDictionary<string, object> values, int id = 0, Guid guid = default, DateTime created = default, DateTime modified = default, EntityPartsBuilder partsBuilder = null)
Parameters
values
IDictionary<string, object>id
intguid
Guidcreated
DateTimemodified
DateTimepartsBuilder
EntityPartsBuilder
Returns
Create(IRawEntity)
Create an entity from a single IRawEntity
IEntity Create(IRawEntity rawEntity)
Parameters
rawEntity
IRawEntity
Returns
Create<T>(IEnumerable<IHasRawEntity<T>>)
Build a complete stream of IRawEntitys. This is the method to use when you don't plan on doing any post-processing.
If you need post-processing, call Prepare
instead and finish using WrapUp
.
IImmutableList<IEntity> Create<T>(IEnumerable<IHasRawEntity<T>> list) where T : IRawEntity
Parameters
list
IEnumerable<IHasRawEntity<T>>
Returns
Type Parameters
T
Create<T>(IEnumerable<T>)
Create a complete list of IRawEntitys. This is the method to use when you don't plan on doing any post-processing.
If you need post-processing, call Prepare
instead and finish using WrapUp
.
IImmutableList<IEntity> Create<T>(IEnumerable<T> list) where T : IRawEntity
Parameters
list
IEnumerable<T>
Returns
Type Parameters
T
New(NoParamOrder, DataFactoryOptions, ILookup<object, IEntity>, RawConvertOptions)
Spawn a new IDataFactory with an initial configuration. This returns a new IDataFactory and will not modify the original/parent. Uses the Spawn New convention.
IDataFactory New(NoParamOrder noParamOrder = default, DataFactoryOptions options = null, ILookup<object, IEntity> relationships = null, RawConvertOptions rawConvertOptions = null)
Parameters
noParamOrder
NoParamOrderoptions
DataFactoryOptionsAll the options which are relevant for the DataFactory
relationships
ILookup<object, IEntity>rawConvertOptions
RawConvertOptionsOptional special options which create-raw might use
Returns
- IDataFactory
Itself, to make call chaining easier
Prepare<T>(IEnumerable<IHasRawEntity<T>>)
This will create IEntity but return it in a dictionary mapped to the original. This is useful when you intend to do further processing and need to know which original matches the generated entity.
IMPORTANT: WIP THIS ALREADY RUNS FullClone, so the resulting IEntities are properly modifiable and shouldn't be cloned again
IList<EntityPair<T>> Prepare<T>(IEnumerable<IHasRawEntity<T>> data) where T : IRawEntity
Parameters
data
IEnumerable<IHasRawEntity<T>>
Returns
- IList<EntityPair<T>>
Type Parameters
T
Prepare<T>(IEnumerable<T>)
This will create IEntity but return it in a dictionary mapped to the original. This is useful when you intend to do further processing and need to know which original matches the generated entity.
IMPORTANT: WIP THIS ALREADY RUNS FullClone, so the resulting IEntities are properly modifiable and shouldn't be cloned again
IList<EntityPair<T>> Prepare<T>(IEnumerable<T> list) where T : IRawEntity
Parameters
list
IEnumerable<T>
Returns
- IList<EntityPair<T>>
Type Parameters
T
Prepare<T>(IHasRawEntity<T>)
For objects which delegate the IRawEntity to a property.
EntityPair<T> Prepare<T>(IHasRawEntity<T> withRawEntity) where T : IRawEntity
Parameters
withRawEntity
IHasRawEntity<T>
Returns
- EntityPair<T>
Type Parameters
T
Prepare<T>(T)
For objects which themselves are IRawEntity
EntityPair<T> Prepare<T>(T rawEntity) where T : IRawEntity
Parameters
rawEntity
T
Returns
- EntityPair<T>
Type Parameters
T
WrapUp(IEnumerable<ICanBeEntity>)
Finalize the work of building something, using prepared materials.
IImmutableList<IEntity> WrapUp(IEnumerable<ICanBeEntity> rawList)
Parameters
rawList
IEnumerable<ICanBeEntity>