I've a question about injecting a service into a domain model, in a way that it'd allow me to instantiate (`new`) that domain model.
Imagine I have a domain model called `Book`. I need to inject a service called `Books` into this domain model, so that I can call the `Books.create()` method from the `Book.create()` method.
If I inject the service dependency in the domain model's constructor, I am not able to `new` that domain model, unless I pass an instance of the service into the domain model.
Domain model:
~~~
class Book {
id: number;
name: string;
constructor (
private Books: Books
){}
create (){
this.Books.create(//pass data here);
}
}
~~~
Component:
~~~
class BooksCreateComponent {
create(){
let book = new Book(); //This fails unless I pass in an instance of Books service.
book.create();
}
}
~~~
Any idea how I should proceed?