Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6652133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:05:54+00:00 2026-05-26T01:05:54+00:00

I have my service layer serving as a facade over my domain model layer

  • 0

I have my service layer serving as a facade over my domain model layer to orchestrate calls to domain objects. I wrote a custome instance provider for my WCF services to harness MEF for instance creation. Now I need to apply PIAB for auditing and logging. How could I do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:05:54+00:00Added an answer on May 26, 2026 at 1:05 am

    Jimmy Tonner has written a nice blog about mixing MEF and PIAB (visit http://blogs.msdn.com/b/jimmytr/archive/2010/06/22/mixing-mef-and-piab.aspx). It inspired my solution to applying PIAB to a MEFied WCF service.
    Idea is simple: use MEF to manage all your service composition first. Then in the custom instance provider, apply PolicyInjection.Wrap after locating the service instance by MEF container. Below is the code sample:

    Service:

    [Export(typeof(ICustomerService))]
    public class CustomerService : ICustomerService
    {
        #region ICustomerService Members
        public Customer GetCustomer(string customerID)
        {
            return CustomerDAO.GetCustomer(customerID);
        }
        #endregion
    }
    

    Custom instance provider:

    public class PolicyInjectionInstanceProvider : IInstanceProvider
    {
        private Type serviceContractType;
    
        private CompositionContainer Container { get; set; } 
    
        public PolicyInjectionInstanceProvider(Type t)
        {
    
            if (t!= null && !t.IsInterface)
            {
                throw new ArgumentException("Specified Type must be an interface");
            }
    
            this.serviceContractType = t;
    
        }
    
        #region IInstanceProvider Members
    
        public object GetInstance(InstanceContext instanceContext, System.ServiceModel.Channels.Message message)
        {
            Type type = instanceContext.Host.Description.ServiceType;
    
            if (serviceContractType != null)
            {
                Compose();
                var importDefinition = new ImportDefinition(i => i.ContractName.Equals(serviceContractType.FullName), serviceContractType.FullName, ImportCardinality.ZeroOrMore, false, false);
                var atomicComposition = new AtomicComposition();
                IEnumerable<Export> extensions;
    
                Container.TryGetExports(importDefinition, atomicComposition, out extensions);
    
                if (extensions != null && extensions.Count() > 0)
                {
                    var service = extensions.First().Value;
                    return PolicyInjection.Wrap(serviceContractType, service);
                }                
            }
            else
            {
                if (!type.IsMarshalByRef)
                {
                    throw new ArgumentException("Type Must inherit MarshalByRefObject if no ServiceInterface is Specified");
                }
                return PolicyInjection.Create(type);
            }
            return null;
        }
    
        public object GetInstance(InstanceContext instanceContext)
        {
            return GetInstance(instanceContext, null);
        }
    
        public void ReleaseInstance(InstanceContext instanceContext, object instance)
        {
            var disposable = instance as IDisposable;
            if (disposable != null)
            {
                disposable.Dispose();
            }
            Container.Dispose();
        }
    
        #endregion
    
        #region Private Methods
    
        private void Compose()
        {
            var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new DirectoryCatalog(@".\")); //Extensions
            Container = new CompositionContainer(catalog);
        }
    
        #endregion
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am designing a WCF service using DDD. I have a domain service layer
I have the following project structure: base project (service layer, model) web project webservice
In my service facade layer, I have a service class with a method/operation that
I have a Web Service ( model-layer ) which communicates with Database. This module
I have this sort of format asp.net MVC View -> Service Layer -> Repository.
For background, I have a Data layer and Service layer loosely based on Rob
I have a service, business and data access layer. In which layer should I
We have a service that has some settings that are supported only over net.tcp.
I am designing a set of 'service' layer objects (data objects and interface definitions)
Is there a simple way to have your Service Layer deployed separately from your

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.