Need simple example for using NWinter...I'm an IOC newbie

10 views
Skip to first unread message

elitz

unread,
Apr 14, 2010, 12:35:42 PM4/14/10
to nicnet
Hello...first time using an IOC container. I have everything setup re:
your documentation...

My code is as follows:

IComponentsConfig config =
System.Configuration.ConfigurationManager.GetSection("components") as
IComponentsConfig;
INamedServiceProvider srv = ((INamedServiceProvider) new
ServiceProvider(config));

((IMyInterfaceName)srv.GetService("MyObjectName")).MyMethodName();

All is want from a configuration standpoint is a way to get a
reference to my service object/type I'm not sure which factory to use
in my config file. (e.g. StaticPropertyInvokingFactory or
MethodInvokingFactory, etc...) I'll then cast the returned object to
an interface i've defined and invoke a method on it. Seems simple but
like i said, i'm new to IOC containers. Can u tell me how my
configuration should work ?

thanks in advance.

Vitalik

unread,
Apr 14, 2010, 12:45:52 PM4/14/10
to nicnet
You can simply define your instance as following (in "components"
section of your app.config file, see
http://code.google.com/p/nicnet/source/browse/trunk/examples/NI.Examples.Winter/App.config
for details):
<component name="MyObjectName" type="[FULL TYPE NAME OF YOUR SERVICE]"
singleton="true">
<property name="SomeProperty"><value>true</value></property>
</component>

Note that you shouldn't use special factory classes like
StaticPropertyInvokingFactory and MethodInvokingFactory for defining
usual component instance (re these classes, they are used for
delegating component instance creation to external factories).

elitz

unread,
Apr 14, 2010, 1:59:03 PM4/14/10
to nicnet
Thank you. So to clarify one point, do i have to use the <property>
attribute ?

So what i have in my config (after reading your reponse) is as
follows:

<components>
<component name="SSISPackage" type="EDIS.SSIS.SSISPackage,
EDIS_SSISPackage" singleton="true">
</component>
</components>

where
-"SSISPackage" is the value i use in the GetService("SSISPackage)
call.
-EDIS.SSIS.SSISPackage is the fully qualified reference to my object
-EDIS_SSISPackage is the name of my assembly file referenced in my
project (EDIS_SSISPackage.dll)


Does this look correct ?

thank you again...


On Apr 14, 10:45 am, Vitalik <fedorche...@gmail.com> wrote:
> You can simply define your instance as following (in "components"

> section of your app.config file, seehttp://code.google.com/p/nicnet/source/browse/trunk/examples/NI.Examp...

Vitalik

unread,
Apr 14, 2010, 2:10:03 PM4/14/10
to nicnet
yes it looks good. Note that in your variant IoC-container will create
instance of EDIS.SSIS.SSISPackage class using default constructor. You
may use <property> tag for injecting property values and <constructor-
arg> for specifying constructor arguments.
You can found more info IoC-containers and injection types here:
http://www.springframework.net/doc-latest/reference/html/objects.html#objects-introduction
Note that in basic things Winter.NET XML configuration is very similar
to Spring.NET syntax (they use "object" tag name, Winter.NET uses
"component" with the same meaning).
Reply all
Reply to author
Forward
0 new messages