Unity.WebAPI | simple integration of Microsoft 's Unity IoC container | Dependency Injection library

 by   devtrends C# Version: Current License: MIT

kandi X-RAY | Unity.WebAPI Summary

kandi X-RAY | Unity.WebAPI Summary

Unity.WebAPI is a C# library typically used in Programming Style, Dependency Injection applications. Unity.WebAPI has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can download it from GitHub.

The easiest way to add Unity.WebApi to your project is via the NuGet package. You can search for unity.webapi using the GUI or type the following into the package manager console in Visual Studio:. Once installed, just add a call to UnityConfig.RegisterComponents() in the Application_Start method of Global.asax.cs and the Web API framework will then use the Unity.WebAPI DependencyResolver to resolve your components. Add your Unity registrations in the RegisterComponents method of the UnityConfig class. All components that implement IDisposable should be registered with the HierarchicalLifetimeManager to ensure that they are properly disposed at the end of the request.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              Unity.WebAPI has a low active ecosystem.
              It has 43 star(s) with 26 fork(s). There are 14 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              There are 0 open issues and 13 have been closed. On average issues are closed in 388 days. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of Unity.WebAPI is current.

            kandi-Quality Quality

              Unity.WebAPI has 0 bugs and 0 code smells.

            kandi-Security Security

              Unity.WebAPI has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              Unity.WebAPI code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              Unity.WebAPI is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              Unity.WebAPI releases are not available. You will need to build from source code and install.
              Installation instructions, examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Unity.WebAPI
            Get all kandi verified functions for this library.

            Unity.WebAPI Key Features

            No Key Features are available at this moment for Unity.WebAPI.

            Unity.WebAPI Examples and Code Snippets

            No Code Snippets are available at this moment for Unity.WebAPI.

            Community Discussions

            QUESTION

            Error occurred when trying to create a controller of type 'EmployeeController'. Make sure controller has a parameterless public constructor
            Asked 2019-Sep-16 at 17:07

            Why I'm I getting this error on Employee Controller rest of them are working perfectly Here is my Employee Controller

            ...

            ANSWER

            Answered 2017-Jul-18 at 08:10

            Make sure that the controller has a parameterless public constructor

            Source https://stackoverflow.com/questions/45160805

            QUESTION

            Unable to resolve dependencies with Unity.AspNet.Mvc in webapi controller
            Asked 2019-Apr-01 at 21:42

            I am using Asp.Net MVC 5 and am trying to wire up my dependencies for a web api controller but it doesnt work and says the controller needs a parameter less constructor.

            I have updated unity container to v4 which meant updating some other references, namely unity.abstractions is also v4.

            I am using unity.mvc not unity.mvc5.

            In UnityConfig I have

            ...

            ANSWER

            Answered 2019-Apr-01 at 21:42

            You will need the Unity.AspNet.WebApi adapter to configure your ApiControllers.

            Careful you don't mix up packages. Some of those are not by the same project owner (Unity.Mvc5, Unity.WebAPI). I haven't used those so I can't comment on its suitability.

            I have a example https://github.com/jasenhk/MovieStar from another answer that uses Unity v5.10 and Unity.MVC as well as Unity.AspNet.WebApi.

            Here is the packages.config

            Source https://stackoverflow.com/questions/55463206

            QUESTION

            IOC in UnitTest class - Unity.WebApi
            Asked 2018-Nov-15 at 15:29

            I have implemented Unity.WebAPI in web api project successfully. Some how new instance of MService class is not being created. I get following error message when i run unit test method.

            Unable to get default constructor for class MServiceTests.

            Service Class

            ...

            ANSWER

            Answered 2018-Nov-15 at 15:20

            You are missing the [TestClass] attribute on the test class (assuming your are using MSTest framework). Test classes need to have an empty default constructor or no constructors at all.

            For setting up the tests you can either arrange it the way that you

            1. Manually create the required instances or
            2. Use a mocking framework or
            3. Do the same initializations just like in your application regarding dependency injection, and then resolve the instances as required

            Maybe you also want to take a look, at the Arrange-Act-Assert pattern for unit tests: (see http://defragdev.com/blog/?p=783)

            Also keep in mind, that you rather want to test the code and not the DI framework.

            Source https://stackoverflow.com/questions/53322104

            QUESTION

            How to access class properties through an Interface instance using Unity.WebApi
            Asked 2018-Nov-14 at 19:31

            Is it possible to expose class public properties in different class through IOC. I am creating an instance of Interface but i am not able to access public properties of class. I am using Unity.WebApi for resolving dependencies.

            TransactionService Class

            ...

            ANSWER

            Answered 2018-Nov-14 at 19:31

            If you are in control of the services then refactor the interfaces to expose the desired members

            Source https://stackoverflow.com/questions/53306471

            QUESTION

            unity dependency error -make sure that the controller has a parameterless public constructor
            Asked 2018-Nov-14 at 17:12

            Sorry i am new to IOC concepts. I have been trying to implement Unity.WebAPI (5.3.0.) in my web api project but getting following error;

            • An error occurred when trying to create a controller of type 'TransactionController'. Make sure that the controller has a parameterless public constructor

            UnityResolver Class

            ...

            ANSWER

            Answered 2018-Nov-14 at 17:12

            Check to make sure that all dependencies for the object graphs have been registered so that they can be resolved correctly.

            You are most likely missing a dependency registration.

            For TransactionService, you are passing/injecting the implementations in the constructors

            Source https://stackoverflow.com/questions/53299895

            QUESTION

            Using Unity Dependency Injection in Multi-User Web Application: Second User to Log In Causes First User To See Second User's Data
            Asked 2018-Oct-15 at 19:41

            I'm trying to implement a web application using ASP.NET MVC and the Microsoft Unity DI framework. The application needs to support multiple user sessions at the same time, each of them with their own connection to a separate database (but all users using the same DbContext; the database schemas are identical, it's just the data that is different).

            Upon a user's log-in, I register the necessary type mappings to the application's Unity container, using a session-based lifetime manager that I found in another question here.

            My container is initialized like this:

            ...

            ANSWER

            Answered 2018-Oct-15 at 17:43

            the issue seems to originate from your registration call, when registering the same type multiple times with unity, the last registration call wins, in this case, that will be data access object for whoever user logs-in last. Unity will take that as the default registration, and will create instances that have the connection to that user's database.

            The SessionLifetimeManager is there to make sure you get only one instance of the objects you resolve under one session.

            One option to solve this is to use named registration syntax to register the data-access types under a key that maps to the logged-in user (could be the database name), and on the resolve side, retrieve this user key, and use it resolve the corresponding data access implementation for the user

            Source https://stackoverflow.com/questions/52821647

            QUESTION

            Unity PerRequestLifetimeManager throwing exception in Web API app in RegisterTypes() method
            Asked 2018-Jun-09 at 22:53

            I configured Unity in my Web API application to inject the dependencies, but it's throwing an exception when I try to register the DbContext with PerRequestLifetimeManager. It works fine if I use the default LifeTimeManager. I have Unity.MVC and Unity.Webapi nuget packages added to the app. Here is the code for RegisterTypes.

            ...

            ANSWER

            Answered 2018-Jun-09 at 22:53

            I figured it out. Just like the error message says, I was trying to inject the DbContext in a non Http Request context at the time of application initialization. It works fine if I do it as shown below, without trying to configure the "InjectionConstructor" inside RegisterType for Repositories. It successfully injects a new instance of DbContext in the repository every request. Seems like you can't use InjectionConstructor for Types that are registered with "PerRequestLifetimeManager".

            Source https://stackoverflow.com/questions/50320903

            QUESTION

            Binding redirect ignored
            Asked 2017-Dec-28 at 23:43

            My website gives...

            Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

            ... and yet in web.config, I have...

            ...

            ANSWER

            Answered 2017-Dec-28 at 23:43

            Many hours later I discovered that this error only appears on my default route and only on my dev machine. It was probably doing it all along and I assumed that something had changed after I re-checked out the code.

            What is a word for this?

            Source https://stackoverflow.com/questions/48010015

            QUESTION

            How implement Strategy/Facade Pattern using Unity Dependecy Injection Web API
            Asked 2017-Oct-06 at 01:05

            How tell to Unity.WebApi dependency injection framework, inject the correct class in the correct controller?

            DI Project Container

            ...

            ANSWER

            Answered 2017-Oct-06 at 01:05

            Rather than using a strategy or facade to solve this, a better solution would be to redesign your interfaces to be unique per controller. Once you have a unique interface type, your DI container will automatically inject the right service into each controller.

            Option 1

            Use a generic interface.

            Source https://stackoverflow.com/questions/41770406

            QUESTION

            When using Unity DI how to add Non DI Service with Entity Framework
            Asked 2017-Sep-12 at 16:17

            This definitely appears to be a different issue than the Multithreading issue.

            Using Unity with Dependency Injection(DI) for all my services and using an entity framework context which appears to be initialized and working correctly.

            Currently using .net 4.5 with mvc and Unity.WebApi and entity framework 6.0.0.0.

            I want to know if its possible to persist a service in this model or use outside of DI and be able to close and re-initialize entity framework in the persisted service if possible.

            Currently getting this error when I try to persist a service through a stack class so its performance will be very fast b/c I'm using more frequently.

            ...

            ANSWER

            Answered 2017-Sep-12 at 16:17

            Since I had stored a copy of my service with my entity's DBContext it was failing because it was being used by multiple threads. The fix was to new it up each time because it had originally came from a Unity DI resolver method and the entity doesn't get newed up each time the stored service and its methods are called.

            Its unknown if the current context can be cleared up a different or better way to make it perform faster when finished with a specific use case scenario in a particular web api thread or end point instead of newing it up in each method call of the saved service.

            Solution every time its stored in a static variable and reused on each method:

            Source https://stackoverflow.com/questions/46160762

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install Unity.WebAPI

            The easiest way to add Unity.WebApi to your project is via the NuGet package. You can search for unity.webapi using the GUI or type the following into the package manager console in Visual Studio:. Once installed, just add a call to UnityConfig.RegisterComponents() in the Application_Start method of Global.asax.cs and the Web API framework will then use the Unity.WebAPI DependencyResolver to resolve your components. Add your Unity registrations in the RegisterComponents method of the UnityConfig class. All components that implement IDisposable should be registered with the HierarchicalLifetimeManager to ensure that they are properly disposed at the end of the request.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/devtrends/Unity.WebAPI.git

          • CLI

            gh repo clone devtrends/Unity.WebAPI

          • sshUrl

            git@github.com:devtrends/Unity.WebAPI.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link