At work we're doing several new web services projects in ServiceStack and taking advantage of Funq in some of them. I'm currently working on a separate project that will consume said web services and was wondering if there was a way for me to use ServiceStack's Funq in my project to resolve my dependencies as to use more or less the same patterns we're using when developing our web services.

Why do you think it is not possible? Funq is a DI container. You can add it to any project.
–
Daniel HilgarthFeb 5 '13 at 14:10

4

Since there's no documentation available from the original project, I have no idea where to even begin. Also, I was wondering about using the version packed with ServiceStack, not the one on CodePlex.
–
enriqueinFeb 5 '13 at 14:31

2 Answers
2

I'm in a similar position, wanting to use heaps of the ServiceStack tools in a non-webby project. I agree that there is a ... slight lack in documentation for Funq

I have been using it in a legacy WinForms app, trying to avoid changing the original project (too much) and I add the new forms to a new project.
I added references to most of the ServiceStack libraries to most of my projects (manually because I'm doing this in .Net 3.5)

Here is the code in the winforms Program.cs file; Note that the FunqContainer is a public static property - I'm still not sure about that, but it gives access across the whole project to the FunqContainer

I like using the lamda in the registration - it defers the construction of objects until they get resolved, rather than at registration time.
By default, the container stores the resolved object as a singleton, but if you have something that needs to be initialized every time it gets used ( ie user controls or winforms ) then use the .ReusedWithin(ReuseScope.None) extension.

ServiceStack includes an enhanced version of Funq (e.g. with AutoWiring support) that's self-contained in the core ServiceStack.dll.

Unfortunately at this time the ServiceStack.dll is contained in the ServiceStack NuGet package which brings in other ServiceStack server dependencies. You can build it from src or cherry pick from the NuGet package just the dlls you need, i.e:

Assuming I'm ok with referencing all necessary ServiceStack dll's, how would I configure it to use it from the app? Will autowiring work even though I won't be using ServiceStack's http handlers?
–
enriqueinFeb 5 '13 at 18:18

Just create a new instance of new Funq.Container() and use the same instance to register and resolve all your deps.
–
mythzFeb 5 '13 at 20:00

np :) I've never tried it without an active AppHost instance, but it's fairly self-contained so you shouldn't have any probs. But if you do get any NullReferenceExceptions post them on github.com/ServiceStack/ServiceStack/issues and we'll sort it out
–
mythzFeb 5 '13 at 20:55