Skip to content

Make NHibernateUtil.Initialize / IsInitialized better reusable for sub-projects like Envers #1515

@DominicUllmann

Description

@DominicUllmann

Hi

NHibernateUtil.Initialize currently support either initializting an INHibernateProxy or an IPersistentCollection. The IPersistentCollection interface is a very big interface and it has so many more reponsibilities than just lazy initialization. Therefore, it would be great if the lazy initialization part could be extracted into a base interface ILazyInitializedCollection which would make it possible to support NHibernateUtil.Initialize / NHibernateUtil.IsInitialized also from other associated projects like NHibernate.Envers.

Supporting the INHibernateProxy initialization from Envers already works, so I tried first to fake the implementation of IPersistentCollection on Envers collection proxies, but that's not feasible as NHibernate.Core uses the IPersistentCollection interface in a lot of type checks unrelated to lazy initialization and thus would require using a real IPersistentCollection implementation.

Therefore I can either create an EnversUtil which provides Initialize / IsInitalized methods or nicer to extract an ILayzInitializedCollection interface from IPerssistentCollection to make NHibernateUtil work with Envers too. As a user of envers, I first expected that it works but realized that it doesn't so I started investigating and tried to patch Envers, but it's not feasible to solve it just on the Envers side.
My current PR for Envers is here:
https://bitbucket.org/RogerKratz/nhibernate.envers/pull-requests/26

It would be great if NHibernate.Core could use the following interface as a base interface of IPersistentCollection and make NHibernateUtil only depending on that:

public partial interface ILazyInitializedCollection
{
	bool WasInitialized { get; }

	void ForceInitialization();
}

Would that be an acceptable change to NHibernate? I will create a PR for that.

Thanks a lot.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions