Unity Dependency Injection - how to register with .config?

This is a C # Asp.net MVC project.

I currently have Unity mappings set in global.asax.cs. I would like to move the container setting from code to web.config.

Everything went fine with my own types, but now I need to translate this line:

container.RegisterInstance (System.Web.Security.Membership.Provider);

(All other configuration lines are container.Register Type ).

I'm not very far. Even if you turn it on

<typeAliases>
    <!-- others elided -->
    <typeAlias
    alias="MembershipProvider"
type="System.Web.Security.MembershipProvider, System.Web"></typeAlias>

he dies with a configuration error:

The value of the property 'type' cannot be parsed. The error is: Could not load file or assembly 'System.Web' or one of its dependencies. The system cannot find the file specified.

So this is rather strange - does it look like he is not looking at the GAC to solve this problem? Or is System.Web not yet included in appdomain?

System.Web bin, : . System.Web.Security.MembershipProvider → System.Web.Security.Membership.Provider

<type type="MembershipProvider" mapTo="System.Web.Security.Membership.Provider, System.Web"></type>

:

"System.Web.Security.Membership.Provider" "System.Web".

, .

.

+3
1

Assembliy?

System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

,

<type type="MembershipProvider" mapTo="System.Web.Security.MembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"></type>

, . "MembershipProvider" .

+5

Source: https://habr.com/ru/post/1706716/


All Articles