4

We're using a custom PublicationResolver to serve content from multiple publications out of a single IIS web application and this setup is working fine for pages.

When I request a binary through the BinaryDistributionModule it always uses the configured DD4T.PublicationId appsetting (through the builtin DefaultPublicationResolver presumably) it doesn't use the custom resolver though.

My DD4T log shows the module is picking up the request:

2014-12-11 13:33:32,706 [18] INFO  DD4T.LogWrappers.Log4Net.Log4NetLogger - >>DistributionModule_OnBeginRequest (/cdn/hofint.com/HoF%20Discovery%20Days%20-%20Day%201_tcm11-1663.pptx)  
2014-12-11 13:33:32,706 [18] INFO  DD4T.LogWrappers.Log4Net.Log4NetLogger - <<DistributionModule_OnBeginRequest (/cdn/hofint.com/HoF%20Discovery%20Days%20-%20Day%201_tcm11-1663.pptx)  
2014-12-11 13:33:32,710 [18] DEBUG DD4T.LogWrappers.Log4Net.Log4NetLogger - Start processing /cdn/hofint.com/HoF%20Discovery%20Days%20-%20Day%201_tcm11-1663.pptx

The cd_core log shows the BinaryMetaFactory looking for the binary in the wrong publication (configured as 9999 as we never use this value so if we see it we know something is wrong):

2014-12-11 13:33:32,711 DEBUG BinaryMetaFactory - Finding binary by url 9999,/cdn/hofint.com/HoF%20Discovery%20Days%20-%20Day%201_tcm11-1663.pptx

As we are using AutoFac as a IoC container i've tried to get various parts of DD4T to use the correct IPublicationResolver:

builder.RegisterType<ComponentFactory>()
    .As<IComponentFactory>()
    .WithProperty("PublicationResolver", new DynamicPublicationResolver())
    .SingleInstance(); 

builder.RegisterType<PageFactory>()
    .As<IPageFactory>()
    .WithProperty("PublicationResolver", new DynamicPublicationResolver());

builder.RegisterType<BinaryFactory>()
    .As<IBinaryFactory>()
    .WithProperty("PublicationResolver", new DynamicPublicationResolver())
    .SingleInstance();

builder.RegisterType<LinkFactory>()
    .As<ILinkFactory>()
    .WithProperty("PublicationResolver", new DynamicPublicationResolver())
    .SingleInstance();

builder.RegisterType<DynamicPublicationResolver>()
    .As<IPublicationResolver>()
    .SingleInstance();

Unfortunately none of the above seems to do the trick for the BinaryDistributionModule and I haven't found any information on how to configure this elsewhere.

Note that I have (of course) tested if the whole setup works at all by temporarily switching the DD4T.PublicationId setting to the "correct" publication...

Lastly my question: how to inform the BinaryDistributionModule to use the custom publication resolver?

2
  • How have you wired up the BinaryDistributionModule with the BinaryFileManager and your IOC? If your IOC doesn't handle the BinaryFileManager (and its dependecies) then you'll get a default BinaryFactory and default Publication resolver.
    – Neil
    Commented Dec 11, 2014 at 13:26
  • The BinaryDistributionModule isn't instantiated through IOC as far as I can tell so how do I tell my IOC to set the property on the BinaryDistributionModule? If the BinaryDistributionModule doesn't actively query the IOC container through the generic service locator to find the underlying items (BinaryFactory, PublicationResolver, etc) the entire IOC approach breaks as there is nothing to hook on to... Commented Dec 11, 2014 at 14:42

2 Answers 2

2

Irrespective of DD4T, you will need a workaround to inject dependencies in HttpModules (see this answer for more), so I think your best bet is to do what you are doing - explicitly setting the resolver in your own implementation of the binary module- its unlikely that you want to change a publication resolver later anyway, and almost every project I worked on customized the default binary module/file manager in any case...

3

Currently I'm using a workaround: by extending the BinaryDistributionModule I can configure the use of a different IPublicationResolver but it's not a very nice solution and sort of defies the purpose of using IoC:

/// <summary>
/// Extension of the BinaryDistributionModule to allow the use of a custom publication resolver.
/// </summary>
public class DynamicBinaryDistributionModule : BinaryDistributionModule
{
    public DynamicBinaryDistributionModule()
    {
        this.BinaryFileManager = new BinaryFileManager()
        {
            BinaryFactory = new BinaryFactory()
            {
                PublicationResolver = new DynamicPublicationResolver()
            }
        };
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.