Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I resolve C# dependencies automatically?

Tags:

c#

unity3d

I've been reading about Unity's dependency injection and I understand it's a thing and that it allows you to type a class to an interface. What I'm curious about is, do I HAVE to? In the below scenario there's a TerrainGenerator and TileCreator in the same space. How can I get the TileCreator within the generator as a dependency?

enter image description here

http://geekswithblogs.net/danielggarcia/archive/2014/01/23/introduction-to-dependency-injection-with-unity.aspx walks me through registering a type, but I read somewhere that as long as the class is visible in the Unity Assets section it'll be able to auto inject it, I just can't figure out the syntax (if it's possible).

Update

I could put all the classes in a single file... with a large system that could be pretty annoying. In the meantime it's an approach I'll try - better than having it not work at all.

update Seems like Unity should be able to look at a class' constructor and perform these resolutions automatically and inject them in my class' constructor. Is that possible?

like image 832
Webnet Avatar asked Jun 14 '16 04:06

Webnet


People also ask

Why does it say C :/ Fakepath?

This is a security feature of the browser. This is designed so the File Upload control does not expose the real file location from your system.

How do I resolve C Fakepath?

To get around it, you can either add the websites you are working with to the Trusted Sites list. Or turn off the option called “Include local directory path when uploading files to a server”. And obviously, adding the sites to the trusted sites list is highly recommended.

What does Fakepath mean when uploading a document?

When a file is chosen using an <input type="file"> , the real path to the source file is not shown in the input's value attribute for obvious security reasons. Instead, the filename is shown, with C:\fakepath\ appended to the beginning of it.

How do I get the original path instead of Fakepath?

If you go to Internet Explorer; Tools; Internet Option; Security; Custom; find the "Include local directory path when uploading files to a server" (it is quite a ways down) and click on "Enable" You may have to restart your computer, but this works & eliminates that "fakepath" that inhibits the upload file path.


1 Answers

If you are looking for DI for the Unity3d engine, maybe this would work (I've not used it, but the feedback is positive) https://github.com/modesttree/Zenject

If you are talking about Microsoft's Unity DI library, you should be able to do this:

container.RegisterTypes(
    AllClasses.FromLoadedAssemblies(),
    WithMappings.FromMatchingInterface,
    WithName.Default);
like image 168
Nate Avatar answered Oct 05 '22 22:10

Nate