C# 使用Nhibernate和Azure Blob的二进制分片模式

C# 使用Nhibernate和Azure Blob的二进制分片模式,c#,.net,nhibernate,azure-storage-blobs,sharding,C#,.net,Nhibernate,Azure Storage Blobs,Sharding,我实际上是用ASP.NETMVC和NHibernate开发一个网站 您可以找到我在GitHub上使用的解决方案的基础示例: 我有图片库来管理NHibernate Microsoft SQL实体。 我的PictureManager调用我的PictureRepository来保存它。 我想在Azure CloudStorage blob中为picture和thunbail切分二进制文件,因此我没有在我的类映射上映射二进制文件字段,但是如何在我当前的体系结构中捕获我的Save Update Delet

我实际上是用ASP.NETMVC和NHibernate开发一个网站

您可以找到我在GitHub上使用的解决方案的基础示例:

我有图片库来管理NHibernate Microsoft SQL实体。 我的PictureManager调用我的PictureRepository来保存它。 我想在Azure CloudStorage blob中为picture和thunbail切分二进制文件,因此我没有在我的类映射上映射二进制文件字段,但是如何在我当前的体系结构中捕获我的Save Update Delete以在不同的支持(CloudStorage)中只保存二进制文件

事实上,我正试图找到解决办法,有什么想法吗

更新

在Pelican给出相关答案后,我想我将使用with Proxy加载二进制文件,并使用拦截器保存/更新/删除

看看我的

你可以用

你可以注册它

new Configuration().SetInterceptor( new TestInterceptor() );

谢谢鹈鹕帮我回答这个问题,我刚刚找到了我想要的:

NHibernate.Proxy.DynamicProxy.ProxyFactory

在IInterceptor.Instance上,您应该选择要放置代理的类

    public override Object Instantiate(String clazz, EntityMode entityMode, Object id)
    {
        if (entityMode == EntityMode.Poco)
        {
            Type type = Type.GetType(clazz, false);

            if (type != null)
            {
                Object instance = CreateProxy(type);

                this.session.SessionFactory.GetClassMetadata(clazz).SetIdentifier(instance, id, entityMode);

                return (instance);
            }
        }

        return (base.Instantiate(clazz, entityMode, id));
    }


    public static Object CreateProxy(Type type)
    {
        List<Type> interfaces = new List<Type>();
        //TODO: add interfaces to list
        interfaces.Add(typeof(IBar));

        Object instance = null;

        if ((interfaces.Count != 0) && (type.IsSealed == false))
        {
            //TODO: pass any custom parameters to the _CustomInterceptor class
            instance = proxyGenerator.CreateProxy(type, new CustomPictureInterceptor(), interfaces.ToArray());
        }
        else
        {
            instance = Activator.CreateInstance(type);
        }

        return (instance);
    }
参考资料:


你看到了吗?是的,Frederic,但是这个例子只在SQL中进行切分,在我的例子中,我希望我的切分在AzureBlobStorage中
    public override Object Instantiate(String clazz, EntityMode entityMode, Object id)
    {
        if (entityMode == EntityMode.Poco)
        {
            Type type = Type.GetType(clazz, false);

            if (type != null)
            {
                Object instance = CreateProxy(type);

                this.session.SessionFactory.GetClassMetadata(clazz).SetIdentifier(instance, id, entityMode);

                return (instance);
            }
        }

        return (base.Instantiate(clazz, entityMode, id));
    }


    public static Object CreateProxy(Type type)
    {
        List<Type> interfaces = new List<Type>();
        //TODO: add interfaces to list
        interfaces.Add(typeof(IBar));

        Object instance = null;

        if ((interfaces.Count != 0) && (type.IsSealed == false))
        {
            //TODO: pass any custom parameters to the _CustomInterceptor class
            instance = proxyGenerator.CreateProxy(type, new CustomPictureInterceptor(), interfaces.ToArray());
        }
        else
        {
            instance = Activator.CreateInstance(type);
        }

        return (instance);
    }
  class CustomPictureInterceptor : NHibernate.Proxy.DynamicProxy.IInterceptor
    {
        public object Intercept(InvocationInfo info)
        {
            //Do what you want
            return info.InvokeMethodOnTarget();
        }
    }