modesttree / Zenject

Dependency Injection Framework for Unity3D

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

upm support

starikcetin opened this issue · comments

Can we convert this into a UPM package to be used with https://github.com/mob-sakai/UpmGitExtension? I can do it for you if you don't have time.

Oh! That's quite cool! I never heard of it.
+1 for the idea.
And you can contribute if you like ;)

Yeah I recently discovered it as well, I will see what I can do.

Alright so here are my current results:
I followed this article: https://www.patreon.com/posts/25070968

The UPM branch is orphan. It is created by git subtree split command.

But instead of leaving the split UPM branch as is, I soft reset to the first commit and squashed everything by amending the commit. This yielded a prettier result in my opinion.

UPM branch: https://github.com/starikcetin/Extenject/tree/upm

The problem is, all the other tags are showing up at the version select list, which are not compatible:
Capture

The reason they are not compatible is that, the UpmGitExtension plugin requires the package.json to be at the repository root, but we cannot just put it in there since we need to only publish the Plugins/Zenject folder as the package.

This is not a huge deal of course, since it rejects you from importing incompatible versions (i.e. when it cannot find the package.json at the repo root). But I think we should find a better way.

Maybe we can maintain a separate repository just for the UPM releases?

Or, maybe we can implement some tag-filtering mechanism in the UpmGitExtension plugin itself, so that it only shows compatible tags. I looked at it for a while but the code seems very complicated.

Alright, can you give me an orphan branch named "upm" here so I can send a pull request @svermeulen ?

Hi @starikcetin

I released UpmGitExtension v1.0.0 with tag filter support.
This is just a short note to inform you. ;)
uge_0_9_1-2
1_0_0_uge-2

Hi @starikcetin

I released UpmGitExtension v1.0.0 with tag filter support.
This is just a short note to inform you. ;)

you know what? you are amazing. :)

@starikcetin Thanks for your contribution! It's much appreciated.
I like the fact that minor updates can be easily distributed to the users of Zenject.

UPM is an awesome thing for the future. However it's still in beta... If you've watched the Unite's Copenhagen there's a lot of new features coming to UPM. Like Asset Store Support, better Git support, etc. But the Package Developer tool is still not available.

The ultimate goal would be to have Zenject/Extenject in the UPM itself. And how cool would it be to have it in the Packages folder!

I am happy to create an UPM branch. But before that... could you enlighten me a bit more?

  • The package installs into the same Plugins/Zenject directory?
  • How does the GitHub link being advertised/registered? Does it automatically show up in the Package Manager? Is there any further action needed?
  • Can updates be made simpler/automated?
  • Does UPM automatically detects updates?
  • Is there anything what can cause a bad user experience?

Don't want to be a pain but just want to get these stuff clear ;)

Btw the package validator gives an error:

Cannot perform upm operation: Unable to add package [https://github.com/starikcetin/Extenject/tree/upm]:
  Package name 'https://github.com/starikcetin/Extenject/tree/upm' is invalid. [InvalidParameter]

Just wanna chime in that I was able to install Extenject from https://github.com/starikcetin/Extenject.git#b2746939227c47de4b00de2a0f772df3d7831e6

Just wanna chime in that I was able to install Extenject from https://github.com/starikcetin/Extenject.git#b2746939227c47de4b00de2a0f772df3d7831e6

hey, you can just use https://github.com/starikcetin/Extenject.git#9.1.0, tag names are also valid.

@Mathijs-Bakker I'll write a detailed response when I get the chance. I've been very busy lately. But shortly, UPM is much better than any other asset sharing method I've used (and I used quite a lot of them). It keeps the assets folder clean of third party imports, provides version based updates with the click of a button, and it supports dependencies!

@Mathijs-Bakker
As this has been uncommented for a while let me try and address your questions:

* The package installs into the same Plugins/Zenject directory?

No, the plugin installs into a Package/Extenject directory. Since the plugin name is pulled from the package defintion this becomes the new diretory name. Also Unity handles upm packages differently and stores them outside the "Assets" directory.

* How does the GitHub link being advertised/registered? Does it automatically show up in the Package Manager? Is there any further action needed?

The package manager does by default not show existing third party projects. Users will need to add the link by themselves.

* Can updates be made simpler/automated?

Yes. I in fact did this via GitHub actions. The workflow implemented on my fork creates a new commit on an orphan upm branch and tags it with a separate upm version tag once a new version tag with the existing semantic versioning theme is pushed to the repo. This approach sadly discards any history as it creates an orphan branch and also creates the need to create separate upm tags but eliminates the need for a second repository compared to the subtree approach.

* Does UPM automatically detects updates?

If you just specify a branch it will always get the head version of that branch. If you use the upm-extension by @mob-sakai it should be able to detect the most recent version. In the newest version it would not detect earlier versions for some reason though (nvm, it detects them fine after adding it, you can downgrade to earlier versions). If you're not using the extension I think you have to manually delete the reference to the used version from the manifest.json.

* Is there anything what can cause a bad user experience?

As previously stated to use the ui you pretty much should use the upm-extension.

Please feel free to correct me if i missed something @starikcetin :)

Hi @umfahrem
Thank you for your reply.
There was a bug with UpmGitExtension. Which didn't allow me to install a git upm.
mob-sakai/UpmGitExtension#73
I will check it later if this has been resolved.

However. UPM should be supported. And actually I have a Zenject UPM version locally. Following Unity's package development recommendations.
I ended up with some optional packages.

  1. Zenject - DI framework
  2. Signals (from optional extras)
  3. Example demos (from optional extras)
  4. Moq Extension (from optional extras)
  5. NSubstitute Extension (from optional extras)

There are still some issues on Unity's side. Because they are still developing their UPM support. There's still something with the dependencies field in the package.js manifesto.

The last months of 2019 have been very busy for me to catch up with a lot of things. And this is one of them. I will see if I can get to it to push the local packages to the according tree.

Meanwhile just keep using the @starikcetin one.

I tried the upm package from @starikcetin but I keep getting spammed with the following warning:

A meta data file (.meta) exists but its asset 'Packages/com.svermeulen.extenject/OptionalExtras/TestFramework/Editor/AutoSubstitute/__MACOSX/AutoSubstitute/NSubstitute' can't be found. When moving or deleting files outside of Unity, please ensure that the corresponding .meta file is moved or deleted along with it.

Note these warnings are usually printed only once if the code is inside your project but in upm packages they keep getting printed over and over.

Note these warnings are usually printed only once if the code is inside your project but in upm packages they keep getting printed over and over.

Yes you right! that's annoying.
More reason to raise this issue on @starikcetin fork

@Mathijs-Bakker I can't, issues are disabled there, and he is not responding

@Mathijs-Bakker I can't, issues are disabled there, and he is not responding

That's bad. However... did you tried to delete the .meta file?
You only see them in your systems file browser window.
And you can open the current directory from right clicking on a file in Unity's project window.
Hope this helps.

Hey, sorry I have been very busy with work and school lately. I will look into it when I get the chance. @paulpach

@starikcetin Thank you for also pushing it to openupm :)

Getting 2 warnings when installing (via openupm) and every time Unity re-focuses:

A meta data file (.meta) exists but its asset 'Packages/com.svermeulen.extenject/OptionalExtras/TestFramework/Editor/AutoSubstitute/__MACOSX/AutoSubstitute/NSubstitute' can't be found. When moving or deleting files outside of Unity, please ensure that the corresponding .meta file is moved or deleted along with it
Couldn't delete Packages/com.svermeulen.extenject/OptionalExtras/TestFramework/Editor/AutoSubstitute/__MACOSX/AutoSubstitute/NSubstitute.meta because it's in an immutable folder.

@starikcetin any progress? that warning is so obnoxious

Can you try 9.1.0-1.metaFileFix version? The warning is gone on my machine.
openupm add com.svermeulen.extenject@9.1.0-1.metaFileFix
@paulpach @MeikelLP

@starikcetin looks good to me

Another issue I have related to UPM:

I cannot use moq.dll right now. I'm using Unity 2019.3.1f1 and set the assembly overrides manually:

image

But I cannot use moq or NSubstitute at all. This might not be an issue with Extenject itself but with the latest Unity package manager. I had a similar bug the other day with testables in the new inputsystem: Unity-Technologies/InputSystem#989 (comment)

Can somebody confirm that this is not possible as of right now?

I can confirm that this is not related to Extenject. Unity generates wrong .csproj files (?)

My references land inside MyProject.Items.csproj instead of MyProject.Items.Tests.csproj -_-

Maybe a dumb question: But does adding Zenject-usage.dll to the assembly refs help?

@Mathijs-Bakker seems to be (another) internal bug in Unity. It's related to

"defineConstraints": [
    "UNITY_INCLUDE_TESTS"
],

if this is not set the dll references work fine. I opened an issue at Unity (Case 1220959). Let's see how it goes.....

So apparently Moq.dll (which I want to use) is not supported in play mode (?).
Do you know if this is something this package can fix or is it an actual Unity issue?

You can use path query parameter from unity2019.3.4f1 and unity2020.1a21.
https://forum.unity.com/threads/some-feedback-on-package-manager-git-support.743345/#post-5425311

Since package.json already exists, it can be set as follows.

{
  "dependencies": {
    "com.svermeulen.extenject": "https://github.com/svermeulen/Extenject.git?path=/UnityProject/Assets/Plugins/Zenject",
    ...
  }
}

When Extenject is installed from Package Manager using path query parameter, the following sample scene cannot be opened.

If you add a samples section to package.json like ShaderGraph, it will be expanded to Assets folder, but an error will occur because the script is duplicated.
https://github.com/Unity-Technologies/Graphics/blob/v7.2.1/com.unity.shadergraph/package.json#L11-L16

If you put sample projects in a hidden folder like Sample~ in upm, it works well, but it will not be included in unitypackage.

Do you have an idea that both unitypackage and upm work?

If you put sample projects in a hidden folder like Sample~ in upm, it works well, but it will not be included in unitypackage.

@shiena I made a PR #220 going right into that trap. Perhaps it could work to rename the folder removing the tilde from the .unitypackage build script?

Hello, is there any chance to release it on OpenUPM to make package installation easier? Releasing it as a package makes updating 1000x easier and more reliable.

I think Unity is also hosting a version of moq via UPM (I've seen it as a dependency in a tiny sample project recently) so adding dependencies like that could be done via UPM as well / OpenUPM

Correct me if I am wrong but isn't there already OpenUPM support?
https://openupm.com/packages/com.svermeulen.extenject/

Or is that another repo?

Yes, it's a fork of Extenject, forked and maintained by starikcetin

Is this still active?
I would really like the solution of a simple "git-link dependency" to this.

@chrPetry use https://openupm.com/packages/com.svermeulen.extenject/

As I understand I would need to add OpenUPM with this solution, right?
I would rather not use OpenUPM but the built-in Unity Package Manager.

@chrPetry use https://openupm.com/packages/com.svermeulen.extenject/

As I understand I would need to add OpenUPM with this solution, right?
I would rather not use OpenUPM but the built-in Unity Package Manager.

OpenUPM is external, it doesn't replace UPM. It is just a tool that automates what you would be doing manually.

My fork is a little outdated however, I don't know when I would get the chance to update it, so be aware.

Unity Package Installer would be a more suitable name.

Unlike its name suggests wat it should do, Unity Package Manager (UPM) does not manage packages for you.
UPM only installs and uninstalls packages.

At Unite 2019 in Copenhagen, the UPM dev team presented the upcoming UPM feats. and their package developer tool. Then it took just a few months before the UPM project was canceled by the board. There are no exact reasons given why this happened (to the outside world). But it has to do something with the fact that UPM would become a competitor of the Unity Asset Store. And Unity needs to make money somewhere.

No other option than OpenUPM

If you want real package managing behavior, as auto update, revert back to earlier versions (tags) then OpenUPM is the only option.

To be continued

Stay tuned...

Alright, then thanks for this info!

upm can also be packaged in a tarball with npm pack, so it can be published to releases as well as unitypackage.
https://docs.unity3d.com/Manual/upm-ui-tarball.html

for example

@Mathijs-Bakker I think the name is somewhat suited. As people can't host packages that are natively supported by UPM, OpenUPM is a free registry users can (with some work involved) upload packages which are free for everybody.

It is very sad that once again Unity is doing stuff very closed and not open to the public.

What's the status of this? The install documentation hints at UPM being an option, but using that installs 9.2.0 whereas we're now at 9.3.1.

What's the status of this? The install documentation hints at UPM being an option, but using that installs 9.2.0 whereas we're now at 9.3.1.

After modest tree won the lawsuit and got control of this repo, they basically just changed the branding and stopped maintaining the repo.

Instaling from @Mathijs-Bakker s maintained fork by git url seems like the best option https://github.com/Mathijs-Bakker/Extenject It's what I'm doing at least

Ah, sorry. I thought I was in the fork :D
It seems to have the same problem but I'll head over there instead.