Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "willignicolas"

Hello,

Any idea ?

Maliming,

IBlobStorage come from the storage.net nuget. An instance is provide by a factory method provided by the nuget and the instance is injected in castle windsor with a name. So it's a singleton.

There is the registration code called twice (for 2 instances of IBlobStorage) in the postInitialize method of my core module :

 IBlobStorage storage = StorageFactory.Blobs.DirectoryFiles(directory);
            _iocManager.IocContainer.Register(
                Castle.MicroKernel.Registration.Component.For<IBlobStorage>().Instance(storage).Named(fileProviderName)
            );

Hope this will help you to find the best implementation.

(It's pity that the register method of IScopedIocResolver do not take a string parameter to resolved the named injected instances)

Thanks for your answer.

I have 9 methods that use FileProvider in my domainservice so I must do that every time ?

Hello,

I have injected Two instances from the same interface like that :

 IBlobStorage storage = StorageFactory.Blobs.DirectoryFiles(directory);
            _iocManager.IocContainer.Register(
                Castle.MicroKernel.Registration.Component.For<IBlobStorage>().Instance(storage).Named(fileProviderName)
            );

I resolve this instance like that :

 FileProvider = _iocManager.IocContainer.Resolve<IBlobStorage>(FileProviderName);

I don't use IIocResolver or IScopedIocResolver because they don't have a resolve method by name but all work fine with that method.

I have read that if i resolve my instances with iocContainer I must release it. I'm in a domainservice context but I don't know where to do the release (I use my instance in many methods in my domain service). I have put a IDisposable interface on my domainservice but the debugger never go to the dispose method.

Have you an idea where to put this release or maybe on other method to resolve the named instance?

Thanks for your help.

Nicolas.

Hello,

I have the exact same problem but I have no '(', ')' or any other special characters in my path.
Did you manage to solve the issue? If yes, how?

Thank you.

Hi,

Thanks for your answer.

No sorry I have not resolved the two issues. Interception of an instance and injection in the instance.

Yes for the injection in the class of the instance component the manual resolve with iocmanager will certainly work thanks.

I have injected my instance component to use interceptor on the first place so I'm still stuck with that for the moment. I have posted the question on stackoverflow (https://stackoverflow.com/questions/57522815/intercept-a-class-instance-with-castle-windsor) and on the support mailling list of castle windsor with no answer for now.

Nicolas.

And on the same subject, a component that is a instancied object seems to cannot have dependency injection in his class.

Is it correct?

Hi ,

I'm trying to implement interceptor on an instantiated class with castle windsor, but no methods are intercepted in this case. All works fine with normally registered components, Castle Windsor intercepts all the methods of my component.

I know that by design Castle Windsor cannot intercept a registered instantiated class, but I was saw this post and tried to implement it with no luck: https://stackoverflow.com/questions/12162769/castle-windsor-cannot-intercept-component-registered-for-a-class-instance

This is my current implementation :

My Factory Interface :

<br>

public interface ITransferProtocolFactory { ITransferProtocol GetTransferProtocol(string transferProtocolName); }

Registration of the factory:

<br>

IocManager.IocContainer.AddFacility<TypedFactoryFacility>(); 
IocManager.IocContainer.Register(Component.For<ITransferProtocolFactory>().AsFactory(new NamedTypeFactory())); 
IocManager.IocContainer.Register(Component.For<NamedTypeFactory, ITypedFactoryComponentSelector>());

Override of the GetComponentName method :

public class NamedTypeFactory : DefaultTypedFactoryComponentSelector 
{
    protected override string GetComponentName(MethodInfo method, object[] arguments)
    {
        string componentName = null;
        if (arguments != null && arguments.Length > 0)
        {
            componentName = arguments[0] as string;
        }
        if (string.IsNullOrEmpty(componentName))
            componentName = base.GetComponentName(method, arguments);
        return componentName;
    }
}

Registering my interceptor :

public static class InterceptorsRegistrar
{
    public static void Initialize(IKernel kernel)
    {
        kernel.ComponentRegistered += Kernel_ComponentRegistered;
    }

    private static void Kernel_ComponentRegistered(string key, IHandler handler)
    {
        if (typeof(ITransferProtocol).IsAssignableFrom(handler.ComponentModel.Implementation) &&
                !typeof(IProxyTransferUserAction).IsAssignableFrom(handler.ComponentModel.Implementation))
        {
            handler.ComponentModel.Interceptors.Add
                (new InterceptorReference(typeof(TransferUserActionInterceptor)));
        }
    }
}

InterceptorsRegistrar.Initialize(IocManager.IocContainer.Kernel);

Creation of instance and registration :

public void CreateAndInjectMachineProtocol(MachineForAgentDto machine)
{
    var machineProtocol = (ITransferProtocol)Activator.CreateInstance(Type.GetType("Agent.Protocols." + Enum.GetName(typeof(eCommunicationType), machine.CommunicationType)));

    _iocManager.IocContainer.Register(Component.For<ITransferProtocol>().Instance(machineProtocol).Named(nameof(ITransferProtocol) + machine.Id.ToString()).LifestyleSingleton());
}

The Interceptor :

<br>

public class TransferUserActionInterceptor : IInterceptor
{
    private readonly IMachineManager _machineManager;

    public TransferUserActionInterceptor(IMachineManager machineManager)
    {
        _machineManager = machineManager;
    }

    public void Intercept(IInvocation invocation)
    {
        invocation.Proceed();
    }
}

And finally the resolver of the component through the factory:

<br>

private ITransferProtocol GetMachineProtocol(long machineId)
{
    return _transferProtocolFactory.GetTransferProtocol(nameof(ITransferProtocol) + machineId.ToString());
}

The Interception is not working in this case because of the design limitation of Castle Windsor.

I have tried to implement this solution https://stackoverflow.com/questions/12162769/castle-windsor-cannot-intercept-component-registered-for-a-class-instance but the interception continue not to working (maybe I have implemented it wrong).

So here are my 2 questions :

How can I implement the stackoverflow post solution on top of my current code to let methods of the ITransferProtocol injected instance be intercepted?

Do you have another solution that the stackoverflow post suggest?

Thanks for your help.

Nicolas

Ok thank you for this information.

I continue to debug though dotnet process.

It's works good.

Yes it works now.

Thank you.

Have you any documentation about that, to anderstand what append?

For the virtual directories outside the mvc website, I have just see on the beginning of our project that files on common, dist and metronic folders are searched on the root of iis (ex: http://localhost/dist/...) so if I not create virtual directory there are not finded in mvc website.

Maybe I have not pointed the good solution?

Thanks again for your help now I'm on the same working situation before the merge with the 7.1.0.

Nicolas

Showing 11 to 20 of 29 entries