AliSoftware / Dip

Simple Swift Dependency container. Use protocols to resolve your dependencies and avoid singletons / sharedInstances!
MIT License
978 stars 75 forks source link

Question on resolving with Tags #165

Closed vander2675 closed 7 years ago

vander2675 commented 7 years ago

Hey, first of all: It's a really great Framework you provide. Thank you very much for it!

And to the question: Is the handing through of the tag only possible when using AutoWiring ? Or is it also possible when using registration like this:

            container.register(.unique) {
                try Load<Chapter, Party>(request: container.resolve(), insert: container.resolve(), save: container.resolve()) as Load<Chapter, Party>
            }

Or do I have to register it this way?

            container.register(.unique) {
                try Load<Chapter, Party>(request: $0 as GenericApiRequest<Party>, insert: $1 as BatchInsert<Chapter, Party>, save: $3 as Save)
            }

Second question:

Is registering with :

            container.register(.unique, type: Load<Media, Chapter>.self, tag: nil, factory: Load<Media, Chapter>.init)

Using AutoWiring?

Thanks very much in advance.

ilyapuchka commented 7 years ago

You can get a tag from context object https://github.com/AliSoftware/Dip/wiki/Dependency-container-context, thats what autowiring does under the hood.

vander2675 commented 7 years ago

Thanks for the quick response. Is Autowiring Constraint to an maximum number of Constructor dependencies?

ilyapuchka commented 7 years ago

yes, the constraint is not on autowiring, it is on registration methods (you can add your own but it is not advised)

vander2675 commented 7 years ago

Ah I see. This was my problem. I will refactor my architecture here. Thank you!

ilyapuchka commented 7 years ago

Regarding you second question - autowiring is a feature to resolve dependencies of constructor without resolving them explicitly in registered factory or manually and passing as parameters to resolve method. So if you resolve this type with resolve it will use autowiring. More on that in docs in wiki.