Search Unity

Any fans of Dependency Injection? New framework released.

Discussion in 'Scripting' started by eventropy, Jun 14, 2014.

  1. eventropy

    eventropy

    Joined:
    Oct 4, 2012
    Posts:
    255
    Updated Zenject to v2.6 which includes:
    • Added new bind methods: ToResource, ToTransientPrefabResource, ToSinglePrefabResource
    • Added ability to have multiple sets of global installers
    • Fixed support for using zenject with .NET 4.5
    • Better support for using the same DiContainer from multiple threads
    • Added back custom list inspector handler to make it easier to re-arrange installers etc.
    • Removed the extension methods on DiContainer to avoid a gotcha that occurs when not including 'using Zenject'
    • Changed to assume any parameters with hard coded default values (eg: int x = 5) are InjectOptional
    • Fixed bug with asteroids project which was causing exceptions to be thrown on the second run due to the use of tags
     
    Grizmu likes this.
  2. eventropy

    eventropy

    Joined:
    Oct 4, 2012
    Posts:
    255
    Updated Zenject to version 3.0

    The major change this release (and why it's 3 instead of 2.9) is that nested containers are a lot more sane and useful now. So the previous support for this in the form of fallback provider / bind scope have been removed. I also added a new concept "Facades" to make use of this feature more easily, and also added better support for WebGL.

    Full Release Notes:

    3.0
    • Nested containers now works more closely to what you might expect: Any parent dependencies are always inherited in sub-containers, even for optional injectables. Also removed BindScope and FallbackContainer since these were really just workarounds for this feature missing. Also added [InjectLocal] attribute for cases where you want to inject dependencies only from the local container.
    • Changed the way execution order is specified in the installers. Now the order for Initialize / Tick / Dispose are all given by one property similar to how unity does it, using ExecutionOrderInstaller
    • Added ability to pass arguments to Container.Install<>
    • Added support for using Facade pattern in combination with nested containers to allow easily created distinct 'islands' of dependencies. See documentation for details
    • Changed validation to be executed on DiContainer instead of through BindingValidator for ease of use
    • Added automatic support for WebGL by marking constructors as [Inject]
    2.8

    • Fixed to properly use explicit default parameter values in Constructor/PostInject methods. For eg: public Foo(int bar = 5) should consider bar to be optional and use 5 if not resolved.
    2.7

    • Bug fix to ensure global composition root always gets initialized before the scene composition root
    • Changed scene decorators to use LoadLevelAdditive instead of LoadLevel to allow more complex setups involving potentially several decorators within decorators
     
    angrypenguin likes this.
  3. janus007

    janus007

    Joined:
    Apr 12, 2016
    Posts:
    5
    I know quite a bit about DI, IOC and addicted to Autofac, but being quite new to Unity3D I've to ask...

    Why should I choose Zenject and not Autofac?
     
  4. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Wow! Just installed Zenject, and loaded the Asteroids 'SampleGame1 (Beginner)' to learn how to better architect my code so that it'll save time down the road. But there are 90 million C# files in there. It'll take me the rest of my life to learn it all.
     
  5. eventropy

    eventropy

    Joined:
    Oct 4, 2012
    Posts:
    255
    Updated Zenject to version 5.0

    Big features in this release include MemoryPools and the Lazy<> construct for lazy resolve. Also includes more changes to make it more accessible to beginner.
     
    Dustin-Horne likes this.
  6. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Is the tutorial on the Github page updated to reflect this accessibility to beginners?
     
  7. eventropy

    eventropy

    Joined:
    Oct 4, 2012
    Posts:
    255
    Yep, docs are up to date. The changes to make it more accessible weren't extensive. Mostly that includes more strict error-checking and better error messages. But I also did a pass on the sample projects to be a bit more understandable, based on your feedback. But they might still be a bit intimidating for some
     
  8. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    I did stumble about this Unite Keynote "Pokemon Go" and it does deliberately not only uses DI but Zenject. I really wanted to share that:


    Disclaimer: I have not yet used zenject, can neither say if it is worth it nor if it isn't. I am just exploring the pros and cons and stumbled upon the question on the first page and the Unite talk. So this is no ad, just sharing a link as answer to the question
     
    eventropy likes this.
  9. eventropy

    eventropy

    Joined:
    Oct 4, 2012
    Posts:
    255
    Updated zenject to Version 5.3.0 which includes:

    - Performance and memory optimizations. In particular, startup time for scenes with many transforms should be significantly reduced.
    - Added new bind methods FromNewComponentOnNewPrefab and FromNewComponentOnNewPrefabResource
    - Added new bind methods for FromSubContainerResolve() bindings: ByNewPrefabMethod, ByNewPrefabResourceMethod, ByNewPrefabInstaller, and ByNewPrefabResourceInstaller
    - Added support for having multiple "parent contract names" for the same scene
    - Added better support for binding open generic types to open generic derived classes
    - Added support for declaring collections of dependencies using IList<> instead of just List<>
    - Changed to skip analyzing unity types (ie. those inside UnityEngine namespace) to minimize reflection costs
    - Fixed AutoMocking to work by upgrading to newer Moq dll
    - Bug fixes
     
    mysticfall likes this.
  10. mysticfall

    mysticfall

    Joined:
    Aug 9, 2016
    Posts:
    649
    I don't have much experience with creating games yet, but from what I've experienced so far I can say it's really useful and it provides quite flexible API, so I'll definitely consider using it for every other Unity projects I might do in future.