Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Dependency Injection


  • Please log in to reply
9 replies to this topic

#1 sfugarino

sfugarino

    Member

  • Members
  • PipPip
  • 29 posts
  • LocationSuwanee, GA

Posted 15 March 2014 - 05:53 PM

Is there anything like Unity that can be used with MF for dependency injection? Also, how does one upload a config file or for that matter any external resource? Do you just add the resource to your project file?

#2 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 15 March 2014 - 06:26 PM

Hi,

 

Not sure what Unity is, but as for config files, I use a .cs file that I then "add->existing item" to the project.

In the .cs file I have a class with everything I might need to change - like GPIO pins, constants and IP addresses.

The class in that file is within a namespace called config - or maybe config_1, config_2, etc. if I have multiple configs.

In my main code, I have a using statement to allow access to the class members.

 

Hope this helps - Paul



#3 sfugarino

sfugarino

    Member

  • Members
  • PipPip
  • 29 posts
  • LocationSuwanee, GA

Posted 15 March 2014 - 10:45 PM

Fair enough. Unity is the dependency injection package in the .NET Enterprise Library. What it does is let you decide at runtime which dependent objects you want to use. You either do that in code or in the config file. Suppose you had two similar sensors. In the classes you write you expose a common interface. Your code picks the correct concrete class to use at runtime by specifying the interface.

#4 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 16 March 2014 - 07:07 AM

Well you (I) learn something new every day.

I only dabble in C#.

 

Thanks - Paul



#5 sfugarino

sfugarino

    Member

  • Members
  • PipPip
  • 29 posts
  • LocationSuwanee, GA

Posted 16 March 2014 - 08:43 AM

Stupid question. If you have a Netduino Plus running a web server, where are the resources stored, i.e, html, images, etc? I suppose you could just write to the response and not have server files or they could be on the sd card. I've worked with .Net a lot, but I really don't know the limitations of the Micro Framework yet.

#6 liqdfire

liqdfire

    Advanced Member

  • Members
  • PipPipPip
  • 78 posts

Posted 16 March 2014 - 05:11 PM

I am not aware of any DI frameworks for NETMF. You may be able to compile an older version of Ninject for the NETMF. Though you may want to re-evaluate your app architecture. While the benefits of using DI on a desktop / web app are widely known, writing code for am embedded device does, and in my opinion should, take a drastically different approach. 

 

These devices are severely resource limited as compared to a desktop / web app. The entirety of your available code space is only 384k on a N+2, the Ninject 4.5 release is 125k by itself. That is a significant amount of code space loss just for a DI framework; additionally, the additional memory requirements for loading and housing the DI framework also needs to be taken into account.

 

If you still feel the need for DI is there, then your best bet would be to roll your own lightweight DI framework, just keep in mind there is no generic support. 

 

As far as config files go, the easiest way it to put an SD card in it, and serialize / deserialize your own format and structure. 



#7 sfugarino

sfugarino

    Member

  • Members
  • PipPip
  • 29 posts
  • LocationSuwanee, GA

Posted 17 March 2014 - 03:36 AM

Old habits are hard to break. I have an Arduino, chipKit Uno32, and Netduino 2. After dealing with the Arduino I felt like the Netduino program space was huge. I'm trying to build an autonomous fish finder and still haven't settled on a platform. Had planed to let the Netduino handle the navigation. I escaped the C++ world over 10 years ago and really like .NET. The development environment alone makes me feel at home, but has me scratching my head every now and then when something isn't available. Going to have to get my mind right.

Thanks for the input.

#8 liqdfire

liqdfire

    Advanced Member

  • Members
  • PipPipPip
  • 78 posts

Posted 18 March 2014 - 11:33 PM

No I completely understand, one case where I could see DI being helpful is if you wrote stubs for devices for use in the simulator instead of debugging on the real hardware. Really rolling a very simple service locator type of DIish is not that hard in that case.

 

You are right, I feel very comfortable in the dev environment but every once in a while I will have to stop and rethink an approach to a task based on supported framework pieces.



#9 sfugarino

sfugarino

    Member

  • Members
  • PipPip
  • 29 posts
  • LocationSuwanee, GA

Posted 19 March 2014 - 11:12 PM

Been reading a lot of Arduino code and I really don't understand how people maintain their code. Global variables all over the place. Code that references variable in a several different file. Even most of the C++ code is just C code presented as C++. No encapsulation, no inheritance, just ugly ass code. One thing you can say about C# is that it is usually readable.

#10 liqdfire

liqdfire

    Advanced Member

  • Members
  • PipPipPip
  • 78 posts

Posted 20 March 2014 - 03:18 AM

Agreed, even though I do not use full DI, all of my netduino app still have very string OO in them.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.