Skip to content

Add a way to pass in dependencies when configuring the LINQ to HQL generator registry class #1669

Open
@nfplee

Description

@nfplee

I'm currently in the process of upgrading a ASP.NET app to use ASP.NET Core and NHibernate 5.1.

When I create the configuration object I say:

var configuration = new Configuration();

configuration.LinqToHqlGeneratorsRegistry<LinqToHqlGeneratorsRegistry>();
configuration.SetInterceptor(new SqlInterceptor(x));

Notice how I can feed dependencies into the constructor of the SqlInterceptor but I cannot do the same for my LinqToHqlGeneratorsRegistry class.

Here's my LinqToHqlGeneratorsRegistry class:

public class LinqToHqlGeneratorsRegistry : DefaultLinqToHqlGeneratorsRegistry {
    public LinqToHqlGeneratorsRegistry() : base() {
        var buildManager = DependencyResolver.Current.GetService<IBuildManager>();

        // Register the method generators
        foreach (var generator in buildManager.GetInstances<BaseHqlGeneratorForMethod>()) {
            this.Merge(generator);
        }

        // Register the property generators
        foreach (var generator in buildManager.GetInstances<BaseHqlGeneratorForProperty>()) {
            this.Merge(generator);
        }
    }
}

This allows me to register my method and property generators in a more modular way. However in .NET Core there is no DependencyResolver. I have found the following https://stackoverflow.com/questions/37813721/asp-net-core-dependencyresolver which describes a way to mimic the DependencyResolver but it still feels like a hack.

Ideally I'd like to be able to feed in an instance of IBuildManager into the constructor of my class.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions