public interface IValuesManager
{
void DoSomething();
}
public class ValuesController : ApiController
{
private IValuesManager _valuesManager { get; set; }
public ValuesController(IValuesManager values)
{
this._valuesManager = values;
}
public void DoSomething()
{}}
For<IValuesManager>().Use<ValuesManager>();
public interface IValuesManager{
Guid UserId { get; set; }
void DoSomething();}public class ValuesController : ApiController{private IValuesManager _valuesManager { get; set; }private int _userId { get; set; }
public ValuesController(IValuesManager values, Guid userId){this._valuesManager = values;
this._userId = userId;
}public void DoSomething(){}......}
For<IValuesManager>()
.Use<ValuesManager>()
.Ctor<Guid>("UserId")
.Is(<< some Guid value goes here>>);
--
You received this message because you are subscribed to the Google Groups "structuremap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-us...@googlegroups.com.
To post to this group, send email to structure...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/structuremap-users/a451ab40-46e8-4e2a-8f36-ede1a5d0d103%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-users+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-us...@googlegroups.com.
To post to this group, send email to structure...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/structuremap-users/a451ab40-46e8-4e2a-8f36-ede1a5d0d103%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "structuremap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-us...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/structuremap-users/83ff1c0a-c276-4178-a68f-b5edb52976f6%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-users+unsub...@googlegroups.com.
To post to this group, send email to structure...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/structuremap-users/a451ab40-46e8-4e2a-8f36-ede1a5d0d103%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "structuremap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-users+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-us...@googlegroups.com.
To post to this group, send email to structure...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/structuremap-users/a451ab40-46e8-4e2a-8f36-ede1a5d0d103%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "structuremap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-us...@googlegroups.com.
To post to this group, send email to structure...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/structuremap-users/83ff1c0a-c276-4178-a68f-b5edb52976f6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "structuremap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-us...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/structuremap-users/c0111afb-9d63-43ec-a495-31bceb5520ad%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-users+unsub...@googlegroups.com.
To post to this group, send email to structure...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/structuremap-users/a451ab40-46e8-4e2a-8f36-ede1a5d0d103%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "structuremap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-users+unsub...@googlegroups.com.
To post to this group, send email to structure...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/structuremap-users/83ff1c0a-c276-4178-a68f-b5edb52976f6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "structuremap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-users+unsub...@googlegroups.com.
Next you give this container to however you are wiring up StructureMap to WebAPI. Google has lots of answers on this topic. I like the child container implemetations. http://benfoster.io/blog/per- request-dependencies-in- aspnet-web-api-using- structuremap. In this case you could likely inject the instance of your ICurrentUser type into the child container.
// childContainer.Inject( currentUserInstance);Hope this helps. I have never actually used WebAPI (yet). I have a project coming down the pipe where It may be forced on me.
On Thu, May 28, 2015 at 7:09 PM, John Bagagem <john...@gmail.com> wrote:
Btw, I'm using StructureMap.WebApi2
On Thursday, May 28, 2015 at 4:50:45 PM UTC-7, John Bagagem wrote:
Any chance you can provide an example of how to solve this?
I've tried a number of approaches but always failing :(
On Thursday, May 28, 2015 at 4:47:26 PM UTC-7, KevM wrote:
Sounds like a good use for child containers. Hasn't this already been solved? Another developer at my work is using WebAPI with structure map 3.
On Thu, May 28, 2015 at 6:44 PM, John Bagagem <john...@gmail.com> wrote:
Hi Kev,
This is going to be a WebApi project that other systems are going to connect to.
The UserId is essential in every call so we want to just want it "registered" as opposed to having to pass it in for every call.
In my example I'm using 1 param, but in reality there are more.
JB
On Thursday, May 28, 2015 at 4:38:32 PM UTC-7, KevM wrote:
Things that you only know at runtime are usually just arguments to methods. What is driving your need for the container to resolve runtime values?
On Thu, May 28, 2015 at 6:22 PM, John Bagagem <john...@gmail.com> wrote:
So basically I have the following - a basic IoC setup with Constructor Injection:public interface IValuesManager
{
void DoSomething();
}
public class ValuesController : ApiController
{
private IValuesManager _valuesManager { get; set; }
public ValuesController( IValuesManager values)
{
this._valuesManager = values;
}
public void DoSomething()
{}}
This is being registered like so:For<IValuesManager>().Use< ValuesManager>();
So far so good, all working OK!
------------------------------ ------------------------------ ------------------------------ ------------------------------
I have some external properties that need to be injected into this class and I will only know the value at runtime. I'll just stick to one property: "UserId". So I will now have the following:public interface IValuesManager{Guid UserId { get; set; }void DoSomething();}public class ValuesController : ApiController{private IValuesManager _valuesManager { get; set; }private int _userId { get; set; }
public ValuesController( IValuesManager values, Guid userId){this._valuesManager = values;
this._userId = userId;}public void DoSomething(){}......}
How can I get this property to be injected given that I don't have a value for it? I've seen some examples of but always with a known value, like so:For<IValuesManager>().Use<ValuesManager>().Ctor<Guid>("UserId").Is(<< some Guid value goes here>>);
------------------------------ ------------------------------ ------------------------------ ------------------------------
Any help guys?
Thanks,
JB
--
You received this message because you are subscribed to the Google Groups "structuremap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-users+ unsub...@googlegroups.com.
To post to this group, send email to structure...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/ msgid/structuremap-users/ a451ab40-46e8-4e2a-8f36- ede1a5d0d103%40googlegroups. com.
For more options, visit https://groups.google.com/d/ optout.
--
You received this message because you are subscribed to the Google Groups "structuremap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-users+ unsub...@googlegroups.com.
To post to this group, send email to structure...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/ msgid/structuremap-users/ 83ff1c0a-c276-4178-a68f- b5edb52976f6%40googlegroups. com.
--
You received this message because you are subscribed to the Google Groups "structuremap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-users+ unsub...@googlegroups.com.
To post to this group, send email to structure...@ googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/ msgid/structuremap-users/ c0111afb-9d63-43ec-a495- 31bceb5520ad%40googlegroups. com.