To the best of my knowledge, Autofac doesn't have a feature to do DI into endpoint behaviors, so you'd have to resolve the dependency manually. (Nick will, I'm sure, jump in here and correct me if I'm wrong.) So in your behavior where you need your IUnitOfWork as a constructor parameter, you'd instead resolve it directly:
public UnitOfWorkEndpointBehavior() { this.unitOfWork = AutofacHostFactory.Container.Resolve<IUnitOfWork>();
}
You can still apply behaviors through XML configuration using Autofac, just like normal, but if you want to do it programmatically you can have a custom host factory based on AutofacServiceHostFactory and use the ConfigurationAction static property
Hmm, The Behaviors takes in IServiceBehavior rather than
IEndpointBehavior
If I set it up to use a ServiceBehavior it get's injected once, and
never again, I guess that the service behavior is newed up once?
The same thing happens with the EndPointBehavior.
I stepped through all the code and it seems that the
CallContextInitializer is created once, and BeforeInvoke/AfterInvoke
are called every request, so I would need to pass a IContainer down to
the CallContextInitializer and resolve a new IUnitOfWork BeforeInvoke
and commit it AfterInvoke.
What has confused me is the article relies on the fact that the
UnitOfWork is created once, and it's role is simply to Open a NH
Session and Transaction, and Commit it later.
I want a new UnitOfWork created for each request which wasn't
happening.
I think I've solved my problem, it's a little bit work, will have to
write my own ServiceBehavior, EndpointBehavior, and
CallContextInitializer, and pass the Autofac IContainer in for it to
resolve the UnitOfWork, but it will do what I want it to do :)
On Nov 4, 3:50 am, Travis Illig <travis.il...@gmail.com> wrote:
> To the best of my knowledge, Autofac doesn't have a feature to do DI into
> endpoint behaviors, so you'd have to resolve the dependency manually. (Nick
> will, I'm sure, jump in here and correct me if I'm wrong.) So in your
> behavior where you need your IUnitOfWork as a constructor parameter, you'd
> instead resolve it directly:
> public UnitOfWorkEndpointBehavior()
> {
> this.unitOfWork = AutofacHostFactory.Container.Resolve<IUnitOfWork>();
> }
> You can still apply behaviors through XML configuration using Autofac, just
> like normal, but if you want to do it programmatically you can have a
> custom host factory based on AutofacServiceHostFactory and use the
> ConfigurationAction static property
> Hmm, The Behaviors takes in IServiceBehavior rather than
> IEndpointBehavior
> If I set it up to use a ServiceBehavior it get's injected once, and
> never again, I guess that the service behavior is newed up once?
> The same thing happens with the EndPointBehavior.
> I stepped through all the code and it seems that the
> CallContextInitializer is created once, and BeforeInvoke/AfterInvoke
> are called every request, so I would need to pass a IContainer down to
> the CallContextInitializer and resolve a new IUnitOfWork BeforeInvoke
> and commit it AfterInvoke.
> What has confused me is the article relies on the fact that the
> UnitOfWork is created once, and it's role is simply to Open a NH
> Session and Transaction, and Commit it later.
> I want a new UnitOfWork created for each request which wasn't
> happening.
> I think I've solved my problem, it's a little bit work, will have to
> write my own ServiceBehavior, EndpointBehavior, and
> CallContextInitializer, and pass the Autofac IContainer in for it to
> resolve the UnitOfWork, but it will do what I want it to do :)
> On Nov 4, 3:50 am, Travis Illig <travis.il...@gmail.com> wrote:
> > To the best of my knowledge, Autofac doesn't have a feature to do DI into
> > endpoint behaviors, so you'd have to resolve the dependency manually. (Nick
> > will, I'm sure, jump in here and correct me if I'm wrong.) So in your
> > behavior where you need your IUnitOfWork as a constructor parameter, you'd
> > instead resolve it directly:
> > You can still apply behaviors through XML configuration using Autofac, just
> > like normal, but if you want to do it programmatically you can have a
> > custom host factory based on AutofacServiceHostFactory and use the
> > ConfigurationAction static property
> This however, seems to work fine. But seems real hacky...
> On Nov 4, 12:10 pm, Phillip Haydon <phillip.hay...@gmail.com> wrote:
> > Hmm, The Behaviors takes in IServiceBehavior rather than
> > IEndpointBehavior
> > If I set it up to use a ServiceBehavior it get's injected once, and
> > never again, I guess that the service behavior is newed up once?
> > The same thing happens with the EndPointBehavior.
> > I stepped through all the code and it seems that the
> > CallContextInitializer is created once, and BeforeInvoke/AfterInvoke
> > are called every request, so I would need to pass a IContainer down to
> > the CallContextInitializer and resolve a new IUnitOfWork BeforeInvoke
> > and commit it AfterInvoke.
> > What has confused me is the article relies on the fact that the
> > UnitOfWork is created once, and it's role is simply to Open a NH
> > Session and Transaction, and Commit it later.
> > I want a new UnitOfWork created for each request which wasn't
> > happening.
> > I think I've solved my problem, it's a little bit work, will have to
> > write my own ServiceBehavior, EndpointBehavior, and
> > CallContextInitializer, and pass the Autofac IContainer in for it to
> > resolve the UnitOfWork, but it will do what I want it to do :)
> > On Nov 4, 3:50 am, Travis Illig <travis.il...@gmail.com> wrote:
> > > To the best of my knowledge, Autofac doesn't have a feature to do DI into
> > > endpoint behaviors, so you'd have to resolve the dependency manually. (Nick
> > > will, I'm sure, jump in here and correct me if I'm wrong.) So in your
> > > behavior where you need your IUnitOfWork as a constructor parameter, you'd
> > > instead resolve it directly:
> > > You can still apply behaviors through XML configuration using Autofac, just
> > > like normal, but if you want to do it programmatically you can have a
> > > custom host factory based on AutofacServiceHostFactory and use the
> > > ConfigurationAction static property
> If anyone has any feedback on it, would be appreciated.
> On Nov 4, 2:47 pm, Phillip Haydon <phillip.hay...@gmail.com> wrote: > > Nope, no luck, passing in the IContainerContext or ILifetimeContext > > and resolving the Unit of Work:
> > This however, seems to work fine. But seems real hacky...
> > On Nov 4, 12:10 pm, Phillip Haydon <phillip.hay...@gmail.com> wrote:
> > > Hmm, The Behaviors takes in IServiceBehavior rather than > > > IEndpointBehavior
> > > If I set it up to use a ServiceBehavior it get's injected once, and > > > never again, I guess that the service behavior is newed up once?
> > > The same thing happens with the EndPointBehavior.
> > > I stepped through all the code and it seems that the > > > CallContextInitializer is created once, and BeforeInvoke/AfterInvoke > > > are called every request, so I would need to pass a IContainer down to > > > the CallContextInitializer and resolve a new IUnitOfWork BeforeInvoke > > > and commit it AfterInvoke.
> > > What has confused me is the article relies on the fact that the > > > UnitOfWork is created once, and it's role is simply to Open a NH > > > Session and Transaction, and Commit it later.
> > > I want a new UnitOfWork created for each request which wasn't > > > happening.
> > > I think I've solved my problem, it's a little bit work, will have to > > > write my own ServiceBehavior, EndpointBehavior, and > > > CallContextInitializer, and pass the Autofac IContainer in for it to > > > resolve the UnitOfWork, but it will do what I want it to do :)
> > > On Nov 4, 3:50 am, Travis Illig <travis.il...@gmail.com> wrote:
> > > > To the best of my knowledge, Autofac doesn't have a feature to do DI > into > > > > endpoint behaviors, so you'd have to resolve the dependency > manually. (Nick > > > > will, I'm sure, jump in here and correct me if I'm wrong.) So in your > > > > behavior where you need your IUnitOfWork as a constructor parameter, > you'd > > > > instead resolve it directly:
> > > > You can still apply behaviors through XML configuration using > Autofac, just > > > > like normal, but if you want to do it programmatically you can have a > > > > custom host factory based on AutofacServiceHostFactory and use the > > > > ConfigurationAction static property
> > > > Then specify the custom UnitOfWorkAutofacHostFactory in your .svc > file as > > > > the service host factory.
> -- > You received this message because you are subscribed to the Google Groups > "Autofac" group. > To post to this group, send email to autofac@googlegroups.com. > To unsubscribe from this group, send email to > autofac+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/autofac?hl=en.
In my service, because unlike MVC I can't find a good spot in WCF to
capture an exception and roll the transaction back. So without
manually capturing all exceptions in code I don't feel it's a
bulletproof solution yet :(
I'm going to have another play this weekend, see if I can find a good
way of being able to roll the transaction back on exception.
Cheers.
Phill
On Nov 7, 1:21 pm, Nicholas Blumhardt <nicholas.blumha...@gmail.com>
wrote:
> > If anyone has any feedback on it, would be appreciated.
> > On Nov 4, 2:47 pm, Phillip Haydon <phillip.hay...@gmail.com> wrote:
> > > Nope, no luck, passing in the IContainerContext or ILifetimeContext
> > > and resolving the Unit of Work:
> > > This however, seems to work fine. But seems real hacky...
> > > On Nov 4, 12:10 pm, Phillip Haydon <phillip.hay...@gmail.com> wrote:
> > > > Hmm, The Behaviors takes in IServiceBehavior rather than
> > > > IEndpointBehavior
> > > > If I set it up to use a ServiceBehavior it get's injected once, and
> > > > never again, I guess that the service behavior is newed up once?
> > > > The same thing happens with the EndPointBehavior.
> > > > I stepped through all the code and it seems that the
> > > > CallContextInitializer is created once, and BeforeInvoke/AfterInvoke
> > > > are called every request, so I would need to pass a IContainer down to
> > > > the CallContextInitializer and resolve a new IUnitOfWork BeforeInvoke
> > > > and commit it AfterInvoke.
> > > > What has confused me is the article relies on the fact that the
> > > > UnitOfWork is created once, and it's role is simply to Open a NH
> > > > Session and Transaction, and Commit it later.
> > > > I want a new UnitOfWork created for each request which wasn't
> > > > happening.
> > > > I think I've solved my problem, it's a little bit work, will have to
> > > > write my own ServiceBehavior, EndpointBehavior, and
> > > > CallContextInitializer, and pass the Autofac IContainer in for it to
> > > > resolve the UnitOfWork, but it will do what I want it to do :)
> > > > On Nov 4, 3:50 am, Travis Illig <travis.il...@gmail.com> wrote:
> > > > > To the best of my knowledge, Autofac doesn't have a feature to do DI
> > into
> > > > > endpoint behaviors, so you'd have to resolve the dependency
> > manually. (Nick
> > > > > will, I'm sure, jump in here and correct me if I'm wrong.) So in your
> > > > > behavior where you need your IUnitOfWork as a constructor parameter,
> > you'd
> > > > > instead resolve it directly:
> > > > > You can still apply behaviors through XML configuration using
> > Autofac, just
> > > > > like normal, but if you want to do it programmatically you can have a
> > > > > custom host factory based on AutofacServiceHostFactory and use the
> > > > > ConfigurationAction static property
> > > > > Then specify the custom UnitOfWorkAutofacHostFactory in your .svc
> > file as
> > > > > the service host factory.
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Autofac" group.
> > To post to this group, send email to autofac@googlegroups.com.
> > To unsubscribe from this group, send email to
> > autofac+unsubscribe@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/autofac?hl=en.
I think this is an interesting feature for adding into Autofac.WcfIntegration, that is the ability to have Autofac handle the creation of EndPointBehaviors. I don't know if it is doable and if WCF provides the wiring for that, but it sure would be useful... Are there any plans for it?
Btw, and since this is my first time posting here, great job on Autofac, absolutely loving it.
> I think this is an interesting feature for adding into > Autofac.WcfIntegration, that is the ability to have Autofac handle the > creation of EndPointBehaviors. I don't know if it is doable and if WCF > provides the wiring for that, but it sure would be useful... Are there any > plans for it?
> Btw, and since this is my first time posting here, great job on Autofac, > absolutely loving it.
> To post to this group, send email to autofac@googlegroups.com. > To unsubscribe from this group, send email to > autofac+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/autofac?hl=en.
In the case of self-hosting you have to add the endpoint behaviors to the Behaviors collection on the service endpoint before opening the service host, so you could resolve any instances of IEndpointBehavior from the container and add them before opening the host manually. For IIS hosting, we could resolve the behaviors from the container for you and add them before opening the service host. Do you have a particular scenario in mind?
Cheers,
Alex.
From: autofac@googlegroups.com [mailto:autofac@googlegroups.com] On Behalf Of Nicholas Blumhardt Sent: Monday, 26 March 2012 1:13 PM To: autofac@googlegroups.com Subject: Re: WCF and IEndpointBehavior
Thanks Kostas. No current plans I'm aware of, but others on this list who spend more time with WCF may have some thoughts here.
Cheers! Nick
On 19 March 2012 23:39, <karampelaskos...@gmail.com> wrote:
Hi Nick,
I think this is an interesting feature for adding into Autofac.WcfIntegration, that is the ability to have Autofac handle the creation of EndPointBehaviors. I don't know if it is doable and if WCF provides the wiring for that, but it sure would be useful... Are there any plans for it?
Btw, and since this is my first time posting here, great job on Autofac, absolutely loving it.
Thanks,
Kostas
-- You received this message because you are subscribed to the Google Groups "Autofac" group.
To post to this group, send email to autofac@googlegroups.com. To unsubscribe from this group, send email to autofac+unsubscribe@googlegroups.com <mailto:autofac%2Bunsubscribe@googlegroups.com> . For more options, visit this group at http://groups.google.com/group/autofac?hl=en.
-- You received this message because you are subscribed to the Google Groups "Autofac" group. To post to this group, send email to autofac@googlegroups.com. To unsubscribe from this group, send email to autofac+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/autofac?hl=en.