Skip to content
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

Injector and hasMapping #310

Open
CrazyFlasher opened this issue Oct 23, 2019 · 2 comments
Open

Injector and hasMapping #310

CrazyFlasher opened this issue Oct 23, 2019 · 2 comments

Comments

@CrazyFlasher
Copy link

How can I get hasClassToValueMapping, hasClassNameToValueMapping, hasClassToTypeMapping, hasClassNameToTypeMapping?

I see only 1 method hasMapping.
What actually it returns? type to class?

@st3veV
Copy link
Collaborator

st3veV commented Oct 23, 2019

It returns true if a type is mapped to something... meaning that injector.getInstance(<Type>) will return a value and not throw an exception.
It doesn't really matter if it is value or type mapping because injector can only have one mapping per type anyway (unless it's named but that's not the point here)

Think of it this way - optional injection is pretty much if(injector.hasMapping(field.type)) field.value = injector.getInstance(field.type); where field is the one that is being injected into.

Does it make sense?

@CrazyFlasher
Copy link
Author

Not exactly. Here is simple example

        var injector:IDependencyInjector = new Injector();

        injector.mapToType(IMockPool_1, MockPool_1);
        Assert.isTrue(injector.hasMapping(IMockPool_1));

        injector.mapToValue(IMockPool_1, injector.getInstance(IMockPool_1));
//        not implemented?
//        Assert.isTrue(injector.hasMappingToValue(IMockPool_1));

        injector.mapClassNameToType("mock.obj.IMockObj_2", MockObj_2);
//        not implemented?
//        Assert.isTrue(injector.hasClassNameMapping("mock.obj.IMockObj_2"));

        var arr:Array<Int> = [1, 2, 3];
        injector.mapClassNameToValue("Array<Int>", arr);
//        not implemented?
//        Assert.isTrue(injector.hasClassNameMappingToValue("Array<Int>"));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants