Code Monkey home page Code Monkey logo

registration-by-convention's People

Contributors

eniks avatar fsimonazzi avatar hannoz avatar s-bauer avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

registration-by-convention's Issues

Support internal classes

It seems that AllClasses doesn't support internal classes (with public interfaces).

Would a PR accepted to support this case?

Add support for searching registrations in assemblies

Support for searching 'registration classes' would be helpful when configuring registrations in a big solution. Registration-by-convention is a big help for general registrations, but custom ones should be written separately. In our solution, we have written such custom registrations in each project in a separate class. To avoid calling those classes manually, auto-search for these 'registration classes' would be helpful.
This functionality can be found in StructureMap:
http://structuremap.github.io/registration/auto-registration-and-conventions/
(See 'Scan for Registries')

How should it look like for us (the users)?

  1. We can create classes which inherit from a unity class (eg. Registry) with one method (or constructor). Within that method, container registrations can be written. This can be useful if registrations-by-convention should be overwritten with a custom registration (for eg. decorators/interceptors)
    Example:
public class FooRegistry : Registry
    {
        public override void Register(IUnityContainer container, Func<LifetimeManager> createLifetimeManager)
        {
            container.RegisterType<IBar, Bar>(createLifetimeManager());
        }
    }
  1. It is possible to specify that unity would search for these type of classes.
    Example:
//separate method
container.SearchForRegistries(lifetimeManager);
//or expanding existing method
container.RegisterTypes(....., SearchForRegistries: true);

Bug ? in public static IUnityContainer RegisterTypes

In the RegisterTypes Method there is this else condition bleow which will register any type
even if i put FromMatchingInterface to the Method.
If the FromMatchingInterface returning Null ( which happens in my App a lot ) anyhow the Method creates a registry entry.

But it should only create a register if for a Class an IClass Interface exists or not ?
So if this is not a Bug how can i avoid this RegisterType of Types where no Interface by anming Convention exists ?

br

            else
            {
                var lifetimeManager = getLifetimeManager(type);
                if (null != lifetimeManager || (null != injectionMembers && 0 < injectionMembers.Length))
                    container.RegisterType(null, type, name, lifetimeManager, injectionMembers);
            }

NuGet Package

Are there any plans to include this alongside the official releases on NuGet?

Load assemblies from base path for web applications

Hi,

The AllClasses.FromAssembliesInBasePath() does not work for web applications.
Since all our applications (web/service/console apps) in the solution use the same container bootstrap logic, it would be nice to let the registration by convention work for all types of applications.

Second: it would be nice to increase the performance of it by providing an overload of this method which can filter the assembly names.

My suggestion is to use code from StructureMap (end-of-life DI container), more specific:
The code in AllClasses.FromAssembliesInBasePath() can use the same code from:
AssemblyFinder.FindAssemblies(func,func,bool)

https://github.com/structuremap/structuremap/blob/master/src/StructureMap/Graph/AssemblyFinder.cs

Result:

  • It always loads the assemblies needed, also for web applications.
  • It is much faster since you can filter the assembly names (eg. fullName.startsWith( "Foo")) before loading each type from the assemblies.

I think this is a quick win for this repo ;)

Please add support for MonoAndroid 8.0 / Xamarin

I cannot install this into my Xamarin project as I am receiving the following error:

Could not install package 'Unity.RegistrationByConvention 2.1.1'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v8.0', but the package does not contain any assembly references or content files that are compatible with that framework.

Thank you

Loading Unity assemblies while registering by convention

I have stumbled upon this issue when i tried to upgrade Unity from 4.0.1 to 5.11.4.

Link to the .NetFiddle

It throws an exception when trying to resolve IContentService
var contentSvc = this._container.Resolve<IContentService>();

My investigation has shown that this is occuring because when registering types with Convention it failed to filter out Unity assemblies and reset the mapping for IUnityContainer <--> UnityContainer which was set in UnityContainer constructor.

Further analysis of this issue revealed that this is happening because of missing GlobalAssemblyInfo.cs file from the new version of Unity which was there in Unity 4.0.1. This global assembly had a common AssemblyProductAttribute which is used to know the Unity framework related assemblies and then to filter them out (in class RegistrationByConvention\src\AllClasses.cs).

Whereas in newer version of Unity each assembly has it own product attribute named after it's assembly title. That's where the comparison failed to check IsUnityAssembly. So except RegistrationByConvention assembly rest all are filtered as Non-Unity assemblies (including Unity.Container, Unity.Abstractions which contains UnityContainer and IUnityContainer) thus resetting the mapping for IUnityContainer.

So whenever a service needed IUnityCOntainer it gets the copy of container which doesn't have the mapping of all available types thus throw the exception.

I am happy to fix this one but not sure the right path for it, like should the GlobalAssemblyInfo be back in newer version or Should it filter assemblies based on AssemblyCompanyAttribute instead of AssemblyProductAttribute.

Reference error with Abstractions

I update the Unity Container(5.10.3) and Unity Abstractions(4.1.3), when i tried to execute de project, it gives me an error. It said that i cant find Abstractions 4.1.1.

The reference with registration-by-convention is bad, could you upload it?

RegisterTypes extension expects LifetimeManager instead of ITypeLifetimeManager

I'm currently working on an upgrade from Unity 3.5 to latest Unity 5.9.x (which is quite a challenge) One of the remaining issues that I have is that the RegisterTypes extension method is used in a few places. First I was glad to find out that it was moved to a separate package, but then I found out that it was using the LifetimeManager, instead of ITypeLifetimeManager that is used now in the standard RegisterType method. The problem is that the lifetime manager is passed a parameter and I had to change the type to ITypeLifetimeManager for all the regular registrations to compile.
So the request is to change signature (or create an overload) of the RegisterTypes extension method to accept ITypeLifetimeManager instead of LifetimeManager

TypeLoadException in v2.1.6

Hello.
I catched exception, when I use RegisterTypes with v2.1.6:
Inheritance security rules violated while overriding member: "Unity.RegistrationByConvention.Exceptions.DuplicateTypeMappingException.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)". Security accessibility of the overriding method must match the security accessibility of the method being overriden.
I use package with Net.Framework 4.6.1.

RegisterTypes extension ignoring 'overwriteExistingMappings' flag

If a type is registered in a Unity container where the interface and class follow the same pattern as used in 'registration by convention', when the RegisterTypes extension is used to register by convention, the original mapping is over-written despite the 'overwriteExistingMappings' flag of the extension method being set to 'false'.

`

        var container = new UnityContainer();
        container.RegisterType<IAppTester, AppTester>(new PerThreadLifetimeManager());

        container.RegisterTypes(
            AllClasses.FromLoadedAssemblies(),
            WithMappings.FromMatchingInterface,
            WithName.Default);

        container.Registrations.First(r => r.RegisteredType.Equals(typeof(IAppTester))).LifetimeManager.GetType().Should().Be<PerThreadLifetimeManager>("specifically registered type should remain");

`

Interception behaviors not cleared when re-registering (bug or by design)

@Minx-SigEp wrote:

I have a large project were my team is using convention based registration to handle the majority of the work. We then re-register a handful of types so we can handle changing lifetime manager and other details about the registration. This second registration of the type does not clear the interception behaviors which causes the behavior to be in the pipeline twice. As a workaround we are finding the IInterceptionBehaviorsPolicy for any type that needs to be re-registered and removing it before re-registering.

I have created a sample project that shows the issue as well as a screen shot. The sample project can be found at https://github.com/Minx-SigEp/UnityInterceptionBug
unityinterception

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.