-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type dependencies #20
Comments
Hi Amit, The new version of Hypodermic takes you by the hand. Basically, when you wrote builder.registerType< Driver >().as< IDriver >();
builder.registerType< Car >(CREATE(new Car(INJECT(IDriver))))
.as< ICar >()
.singleInstance(); now you can write builder.registerType< Driver >().as< IDriver >(); because you no longer need to describe the look of the constructor of Car. More specifically, you only have to register types when you need to configure them. That is, their lifetime, or when they have to be known as an interface, or they have a very specific constructor not accepting instance types that Hypodermic can inject. As a last example, if IDriver didn’t exist, well, if Car was accepting a Driver, you could only describe Car builder.registerType< Car >().as< ICar >().singleInstance(); and if Car didn’t need to be known as ICar or be a single instance, you could just resolve Car without registering anything (doing so is harmless of course). If you have any further questions, feel free to get back to me. Thanks for the cheerings, it is always appreciated. |
Thanks Yohan, I tried following your guidelines, and i'm getting this error: ContainerBuilder.h:27:81: required by substitution of 'template<class T> typename
Hypodermic::RegistrationDescriptorBuilder::ForTypeConstruction<T>::Type&
Hypodermic::ContainerBuilder::registerType() [with T = FG::S2CMessageDispatcher]'
static assertion failed: Could not autowire T: you should consider registering T either by
providing an instance or an instance factory on this line: builder.registerType< S2CMessageDispatcher >().as< IS2CMessageDispatcher >().singleInstance(); This is the class: class S2CMessageDispatcher : public IS2CMessageDispatcher as you can see - it's implementing Can you help me understand what's the issue? Thanks, |
Can you show me the ctor of your class? (Is it public?) |
It looks something like this:
..... |
I assume the order in which i register the types doesn't matter, right? |
It doesn't. |
Well, this is it. Have a look at Hypodermic is configured to inject up to 20 dependencies by default. You might be able to raise it to whatever the number you want. |
That solved it, thanks. i had a registration like this: builder.registerType< CommandlineParser >
(
[=](IComponentContext&)
{
return new CommandlineParser(argc, argv);
}
).as< ICommandlineParser >().singleInstance(); How should i implement it now? |
Is it equivelent to this: builder.registerInstanceFactory
(
[=](Container&)
{
return std::make_shared< CommandlineParser >(argc, argv);
}
).singleInstance(); If i try this - i'm getting this compilation error: /home/amitkanfer/dev/unified_fireglass/vb/3rd_party/Hypodermic/
ProvidedInstanceFactoryRegistrationDescriptor.h:65:50: error: this context->m_instanceFactory =
m_instanceFactory; thanks alot :) |
Yes, so I should investigate... What kind of unit test can I build to make this fails like your code? |
Thank you very much for pointing out this issue. You are all set. Thanks again |
Thanks alot! |
Hello there,
Thanks for the very cool project.
Question 1:
I've been using the version you've published in the past, using the
INJECT
macro in order to declare dependencies of a type.So for example:
in this example, i need to be familiar only with the
IDriver
interface.I see that you changed this implementation and now the above should look something like this:
right?
But now it seems like i need to be familiar with both
IDriver
andDriver
Am i missing something?
Question 2:
Does the new version compiles faster comparing to the previous release?
Thanks alot,
Amit
The text was updated successfully, but these errors were encountered: