George Mylonas
George Mylonas

Reputation: 722

Symfony2 sharing entities in multiple bundles

In my project I have API Bundle and Dashboard Bundle where I reuse Entities like Client, User, Store etc in both bundles. All entities are in API Bundle at the moment, however I have a feeling that they should be stored in a different Bundle, something like Generic Bundle.

Does anyone has a Best Practice for that?

I read this question about relationships, but it speaks about relationships and not Best Practice.

Thanks.

Upvotes: 1

Views: 906

Answers (1)

Tom Tom
Tom Tom

Reputation: 3698

I don't think there is really one best practice here but the key is re-usability. Let's say down the road for some reason you decide to run the API & Dashboard as 2 separate services. Having a UserBundle with your Client & User Entities means you'll just need to install that on both services along with either the API or Dashboard bundle. You could then also have a service with only your UserBundle that handles the login, ect... Same thing for the Store, I would personally decouple that as much as I could.

But the real question is if it is necessary ? Would you reuse that UserBundle in another project ? Do you plan on splitting the project as services down the road ?

Ultimately the specifics are really up to you, a GenericBundle could be all you need or you might have enough to separate into UserBundle & StoreBundle for example.

Upvotes: 2

Related Questions