Here is an implementation that works, thank you for the tips

I've one question : Is it correct to create a DefaultLifetimeScope, or
there is a way to retrieve one already created ? (See my implementation
below) Because you write [ThreadStatic] so I put it as a static property.

Also, I didn't find a way to make a generic scope that take a base scope
(WcfOperationScopeAccessor) and a fallback scope, because when registering
the component I didn't find a way to register the scope accessor with an
existing object:

            return
componentRegistration.LifestyleScoped<WcfOperationOrTransientScopeAccessor>();

It could be useful to register like this:

            var scopeAccessor = new
GenericScopeWithFallback<WcfOperationOrTransientScopeAccessor>(new
DefaultLifetimeScope());
            return componentRegistration.LifestyleScoped(scopeAccessor);

But anyway, it's not very important as it's just an easier way, and I think
I could also make it something like this but I've not yet tried

            return
componentRegistration.LifestyleScoped<WcfOperationOrTransientScopeAccessor<DefaultLifetimeScope>>();


My implementation:

    public class WcfOperationOrTransientScopeAccessor : IScopeAccessor
    {        #region Declarations
        private static DefaultLifetimeScope _defaultLifetimeScope;
        private WcfOperationScopeAccessor _wcfOperationScopeAccessor;
       #endregion
         #region Properties
        protected static DefaultLifetimeScope DefaultLifetimeScope
        {
            get
            {
                if (_defaultLifetimeScope == null)
                    _defaultLifetimeScope = new DefaultLifetimeScope();
                return _defaultLifetimeScope;
            }
        }

        protected WcfOperationScopeAccessor WcfOperationScope
        {
            get
            {
                if (this._wcfOperationScopeAccessor == null)
                    this._wcfOperationScopeAccessor = new
WcfOperationScopeAccessor();
                return this._wcfOperationScopeAccessor;
            }
        }         #endregion
         #region IScopeAccessor implementation
        public ILifetimeScope GetScope(CreationContext context)
        {
            var wcfScope = this.WcfOperationScope.GetScope(context);
            if (wcfScope != null)
                return wcfScope;
            return DefaultLifetimeScope;
        }

        public void Dispose()
        {
            this.WcfOperationScope.Dispose();
        }         #endregion
    }






On Thu, May 17, 2012 at 7:12 PM, Craig Neuwirt <[email protected]> wrote:

> You would then use
>
> registration.LifeStyle.Scoped<YourScopeAccessor>();
>
> to register your component
> On May 17, 2012, at 11:41 AM, Fabrice wrote:
>
>
>
> On Thu, May 17, 2012 at 5:28 PM, Craig Neuwirt <[email protected]> wrote:
>
>>
>> It is certainly possible to do that and off the top of my head, I believe
>> the prior version did that.  As mentioned above, that is the wrong behavior
>> since it would be inconsistent.
>> What I currently do is register the components with the general Scoped
>> lifestyle and explicitly control the boundary of the scope.  The
>> Container/Kernel has a BeginScope extension method which will start the
>> scope and on disposal remove it.   I then put hooks in ASP.NET to begin
>> the scope.     I use that option to control my data access as well.
>>
>>
> I can't use BeginScope because I don't have a strong reference to castle,
> my application only use a IServiceProvider ... so I would like to only use
> registration/configuration and let the component resolution as it is now.
>
> I've searched on how to create a custom lifestyle, but all sample I've
> found is for previous Castle version
> The best will be to use a sort of Composite lifestyle that take a main
> lifestyle and one (or several) fallback lifestyle. It'll better to not
> rewrite existing stuff (like PerWcfOperation & Transient) and instead reuse
> it.
> Do you have any tips on how to do that ?
>
> I've tried to understand the code available in
> https://github.com/castleproject/Castle.Facilities.Wcf-READONLY/tree/master/src/Castle.Facilities.WcfIntegration/Lifestylesbut
>  I'm not sure it's the latest code for Castle 3 ?
>
> Thanks for your help
> Fabrice
>
> --
> You received this message because you are subscribed to the Google Groups
> "Castle Project Users" group.
> To post to this group, send email to [email protected]
> .
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/castle-project-users?hl=en.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Castle Project Users" group.
> To post to this group, send email to [email protected]
> .
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/castle-project-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to