c# Unity Container Name
I want to get the unity container(created using Load Configuration) name using code.
Named container is loaded using config file and I need see the name of the container.
Is it possible?
Thanks!!!
c# unity-container
add a comment |
I want to get the unity container(created using Load Configuration) name using code.
Named container is loaded using config file and I need see the name of the container.
Is it possible?
Thanks!!!
c# unity-container
I am not sure about this but just having way around of this problem. While registering the classes into the container you can inject the Container name into the class property so that while resolving the class you may access the property of the class which actually contains the name of the container.
– Himanshu Jain
Jun 18 '16 at 11:25
add a comment |
I want to get the unity container(created using Load Configuration) name using code.
Named container is loaded using config file and I need see the name of the container.
Is it possible?
Thanks!!!
c# unity-container
I want to get the unity container(created using Load Configuration) name using code.
Named container is loaded using config file and I need see the name of the container.
Is it possible?
Thanks!!!
c# unity-container
c# unity-container
asked Jun 18 '16 at 10:00
DeepakDeepak
6219
6219
I am not sure about this but just having way around of this problem. While registering the classes into the container you can inject the Container name into the class property so that while resolving the class you may access the property of the class which actually contains the name of the container.
– Himanshu Jain
Jun 18 '16 at 11:25
add a comment |
I am not sure about this but just having way around of this problem. While registering the classes into the container you can inject the Container name into the class property so that while resolving the class you may access the property of the class which actually contains the name of the container.
– Himanshu Jain
Jun 18 '16 at 11:25
I am not sure about this but just having way around of this problem. While registering the classes into the container you can inject the Container name into the class property so that while resolving the class you may access the property of the class which actually contains the name of the container.
– Himanshu Jain
Jun 18 '16 at 11:25
I am not sure about this but just having way around of this problem. While registering the classes into the container you can inject the Container name into the class property so that while resolving the class you may access the property of the class which actually contains the name of the container.
– Himanshu Jain
Jun 18 '16 at 11:25
add a comment |
1 Answer
1
active
oldest
votes
You can use the following code to get name of container (if you named it in config file)
#region StaticVariables
public static IUnityContainer unityContainer get; set;
#endregion
#region StaticMethod
static void Main(string args)
unityContainerRegistration.LifetimeManager.InUse ");
#endregion
Configuration file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Unity.Configuration"/>
</configSections>
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<alias alias="IOperation" type="Unity.IOperation, Unity" />
<alias alias="ILogger" type="Unity.ILogger, Unity" />
<alias alias="ConsoleLogger" type="Unity.ConsoleLogger, Unity" />
<alias alias="FileLogger" type="Unity.FileLogger, Unity" />
<alias alias="AddOperation" type="Unity.AddOperation, Unity" />
<alias alias="SubtractOperation" type="Unity.SubtractOperation, Unity" />
<alias alias="MultiplyOperation" type="Unity.MultiplyOperation, Unity" />
<alias alias="DivideOperation" type="Unity.DivideOperation, Unity" />
<alias alias="QuotientOperation" type="Unity.QuotientOperation, Unity" />
<alias alias="LoggingCallHandler" type="Logger.CallHandler.LoggingCallHandler, Unity" />
<alias alias="LoggingInterceptionBehavior" type="Logger.InstanceInterception.LoggingInterceptionBehavior, Unity" />
<namespace name="Unity" />
<assembly name="Unity" />
<sectionExtension type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension, Unity.Interception.Configuration"/>
<container>
<extension type="Interception"/>
<!--<register type="LoggingCallHandler" />-->
<register type="ILogger" mapTo="ConsoleLogger" />
<register name="ApplicationLogger" type="ILogger" mapTo="ConsoleLogger" />
<register name="+" type="IOperation" mapTo="AddOperation">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="LoggingInterceptionBehavior"/>
</register>
<register name="-" type="IOperation" mapTo="SubtractOperation">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="LoggingInterceptionBehavior"/>
</register>
<register name="*" type="IOperation" mapTo="MultiplyOperation" />
<register name="/" type="IOperation" mapTo="DivideOperation" />
<register name="%" type="IOperation" mapTo="QuotientOperation" />
<register name="plus" type="IOperation" mapTo="AddOperation">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="LoggingInterceptionBehavior"/>
</register>
<register name="minus" type="IOperation" mapTo="SubtractOperation">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="LoggingInterceptionBehavior"/>
</register>
<register name="multiply" type="IOperation" mapTo="MultiplyOperation" />
<register name="divide" type="IOperation" mapTo="DivideOperation" />
<register name="remainder" type="IOperation" mapTo="QuotientOperation" />
</container>
</unity>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37895704%2fc-sharp-unity-container-name%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use the following code to get name of container (if you named it in config file)
#region StaticVariables
public static IUnityContainer unityContainer get; set;
#endregion
#region StaticMethod
static void Main(string args)
unityContainerRegistration.LifetimeManager.InUse ");
#endregion
Configuration file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Unity.Configuration"/>
</configSections>
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<alias alias="IOperation" type="Unity.IOperation, Unity" />
<alias alias="ILogger" type="Unity.ILogger, Unity" />
<alias alias="ConsoleLogger" type="Unity.ConsoleLogger, Unity" />
<alias alias="FileLogger" type="Unity.FileLogger, Unity" />
<alias alias="AddOperation" type="Unity.AddOperation, Unity" />
<alias alias="SubtractOperation" type="Unity.SubtractOperation, Unity" />
<alias alias="MultiplyOperation" type="Unity.MultiplyOperation, Unity" />
<alias alias="DivideOperation" type="Unity.DivideOperation, Unity" />
<alias alias="QuotientOperation" type="Unity.QuotientOperation, Unity" />
<alias alias="LoggingCallHandler" type="Logger.CallHandler.LoggingCallHandler, Unity" />
<alias alias="LoggingInterceptionBehavior" type="Logger.InstanceInterception.LoggingInterceptionBehavior, Unity" />
<namespace name="Unity" />
<assembly name="Unity" />
<sectionExtension type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension, Unity.Interception.Configuration"/>
<container>
<extension type="Interception"/>
<!--<register type="LoggingCallHandler" />-->
<register type="ILogger" mapTo="ConsoleLogger" />
<register name="ApplicationLogger" type="ILogger" mapTo="ConsoleLogger" />
<register name="+" type="IOperation" mapTo="AddOperation">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="LoggingInterceptionBehavior"/>
</register>
<register name="-" type="IOperation" mapTo="SubtractOperation">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="LoggingInterceptionBehavior"/>
</register>
<register name="*" type="IOperation" mapTo="MultiplyOperation" />
<register name="/" type="IOperation" mapTo="DivideOperation" />
<register name="%" type="IOperation" mapTo="QuotientOperation" />
<register name="plus" type="IOperation" mapTo="AddOperation">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="LoggingInterceptionBehavior"/>
</register>
<register name="minus" type="IOperation" mapTo="SubtractOperation">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="LoggingInterceptionBehavior"/>
</register>
<register name="multiply" type="IOperation" mapTo="MultiplyOperation" />
<register name="divide" type="IOperation" mapTo="DivideOperation" />
<register name="remainder" type="IOperation" mapTo="QuotientOperation" />
</container>
</unity>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
add a comment |
You can use the following code to get name of container (if you named it in config file)
#region StaticVariables
public static IUnityContainer unityContainer get; set;
#endregion
#region StaticMethod
static void Main(string args)
unityContainerRegistration.LifetimeManager.InUse ");
#endregion
Configuration file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Unity.Configuration"/>
</configSections>
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<alias alias="IOperation" type="Unity.IOperation, Unity" />
<alias alias="ILogger" type="Unity.ILogger, Unity" />
<alias alias="ConsoleLogger" type="Unity.ConsoleLogger, Unity" />
<alias alias="FileLogger" type="Unity.FileLogger, Unity" />
<alias alias="AddOperation" type="Unity.AddOperation, Unity" />
<alias alias="SubtractOperation" type="Unity.SubtractOperation, Unity" />
<alias alias="MultiplyOperation" type="Unity.MultiplyOperation, Unity" />
<alias alias="DivideOperation" type="Unity.DivideOperation, Unity" />
<alias alias="QuotientOperation" type="Unity.QuotientOperation, Unity" />
<alias alias="LoggingCallHandler" type="Logger.CallHandler.LoggingCallHandler, Unity" />
<alias alias="LoggingInterceptionBehavior" type="Logger.InstanceInterception.LoggingInterceptionBehavior, Unity" />
<namespace name="Unity" />
<assembly name="Unity" />
<sectionExtension type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension, Unity.Interception.Configuration"/>
<container>
<extension type="Interception"/>
<!--<register type="LoggingCallHandler" />-->
<register type="ILogger" mapTo="ConsoleLogger" />
<register name="ApplicationLogger" type="ILogger" mapTo="ConsoleLogger" />
<register name="+" type="IOperation" mapTo="AddOperation">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="LoggingInterceptionBehavior"/>
</register>
<register name="-" type="IOperation" mapTo="SubtractOperation">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="LoggingInterceptionBehavior"/>
</register>
<register name="*" type="IOperation" mapTo="MultiplyOperation" />
<register name="/" type="IOperation" mapTo="DivideOperation" />
<register name="%" type="IOperation" mapTo="QuotientOperation" />
<register name="plus" type="IOperation" mapTo="AddOperation">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="LoggingInterceptionBehavior"/>
</register>
<register name="minus" type="IOperation" mapTo="SubtractOperation">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="LoggingInterceptionBehavior"/>
</register>
<register name="multiply" type="IOperation" mapTo="MultiplyOperation" />
<register name="divide" type="IOperation" mapTo="DivideOperation" />
<register name="remainder" type="IOperation" mapTo="QuotientOperation" />
</container>
</unity>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
add a comment |
You can use the following code to get name of container (if you named it in config file)
#region StaticVariables
public static IUnityContainer unityContainer get; set;
#endregion
#region StaticMethod
static void Main(string args)
unityContainerRegistration.LifetimeManager.InUse ");
#endregion
Configuration file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Unity.Configuration"/>
</configSections>
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<alias alias="IOperation" type="Unity.IOperation, Unity" />
<alias alias="ILogger" type="Unity.ILogger, Unity" />
<alias alias="ConsoleLogger" type="Unity.ConsoleLogger, Unity" />
<alias alias="FileLogger" type="Unity.FileLogger, Unity" />
<alias alias="AddOperation" type="Unity.AddOperation, Unity" />
<alias alias="SubtractOperation" type="Unity.SubtractOperation, Unity" />
<alias alias="MultiplyOperation" type="Unity.MultiplyOperation, Unity" />
<alias alias="DivideOperation" type="Unity.DivideOperation, Unity" />
<alias alias="QuotientOperation" type="Unity.QuotientOperation, Unity" />
<alias alias="LoggingCallHandler" type="Logger.CallHandler.LoggingCallHandler, Unity" />
<alias alias="LoggingInterceptionBehavior" type="Logger.InstanceInterception.LoggingInterceptionBehavior, Unity" />
<namespace name="Unity" />
<assembly name="Unity" />
<sectionExtension type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension, Unity.Interception.Configuration"/>
<container>
<extension type="Interception"/>
<!--<register type="LoggingCallHandler" />-->
<register type="ILogger" mapTo="ConsoleLogger" />
<register name="ApplicationLogger" type="ILogger" mapTo="ConsoleLogger" />
<register name="+" type="IOperation" mapTo="AddOperation">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="LoggingInterceptionBehavior"/>
</register>
<register name="-" type="IOperation" mapTo="SubtractOperation">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="LoggingInterceptionBehavior"/>
</register>
<register name="*" type="IOperation" mapTo="MultiplyOperation" />
<register name="/" type="IOperation" mapTo="DivideOperation" />
<register name="%" type="IOperation" mapTo="QuotientOperation" />
<register name="plus" type="IOperation" mapTo="AddOperation">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="LoggingInterceptionBehavior"/>
</register>
<register name="minus" type="IOperation" mapTo="SubtractOperation">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="LoggingInterceptionBehavior"/>
</register>
<register name="multiply" type="IOperation" mapTo="MultiplyOperation" />
<register name="divide" type="IOperation" mapTo="DivideOperation" />
<register name="remainder" type="IOperation" mapTo="QuotientOperation" />
</container>
</unity>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
You can use the following code to get name of container (if you named it in config file)
#region StaticVariables
public static IUnityContainer unityContainer get; set;
#endregion
#region StaticMethod
static void Main(string args)
unityContainerRegistration.LifetimeManager.InUse ");
#endregion
Configuration file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Unity.Configuration"/>
</configSections>
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<alias alias="IOperation" type="Unity.IOperation, Unity" />
<alias alias="ILogger" type="Unity.ILogger, Unity" />
<alias alias="ConsoleLogger" type="Unity.ConsoleLogger, Unity" />
<alias alias="FileLogger" type="Unity.FileLogger, Unity" />
<alias alias="AddOperation" type="Unity.AddOperation, Unity" />
<alias alias="SubtractOperation" type="Unity.SubtractOperation, Unity" />
<alias alias="MultiplyOperation" type="Unity.MultiplyOperation, Unity" />
<alias alias="DivideOperation" type="Unity.DivideOperation, Unity" />
<alias alias="QuotientOperation" type="Unity.QuotientOperation, Unity" />
<alias alias="LoggingCallHandler" type="Logger.CallHandler.LoggingCallHandler, Unity" />
<alias alias="LoggingInterceptionBehavior" type="Logger.InstanceInterception.LoggingInterceptionBehavior, Unity" />
<namespace name="Unity" />
<assembly name="Unity" />
<sectionExtension type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension, Unity.Interception.Configuration"/>
<container>
<extension type="Interception"/>
<!--<register type="LoggingCallHandler" />-->
<register type="ILogger" mapTo="ConsoleLogger" />
<register name="ApplicationLogger" type="ILogger" mapTo="ConsoleLogger" />
<register name="+" type="IOperation" mapTo="AddOperation">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="LoggingInterceptionBehavior"/>
</register>
<register name="-" type="IOperation" mapTo="SubtractOperation">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="LoggingInterceptionBehavior"/>
</register>
<register name="*" type="IOperation" mapTo="MultiplyOperation" />
<register name="/" type="IOperation" mapTo="DivideOperation" />
<register name="%" type="IOperation" mapTo="QuotientOperation" />
<register name="plus" type="IOperation" mapTo="AddOperation">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="LoggingInterceptionBehavior"/>
</register>
<register name="minus" type="IOperation" mapTo="SubtractOperation">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="LoggingInterceptionBehavior"/>
</register>
<register name="multiply" type="IOperation" mapTo="MultiplyOperation" />
<register name="divide" type="IOperation" mapTo="DivideOperation" />
<register name="remainder" type="IOperation" mapTo="QuotientOperation" />
</container>
</unity>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
answered Nov 14 '18 at 5:53
Ashokan SivapragasamAshokan Sivapragasam
346111
346111
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37895704%2fc-sharp-unity-container-name%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I am not sure about this but just having way around of this problem. While registering the classes into the container you can inject the Container name into the class property so that while resolving the class you may access the property of the class which actually contains the name of the container.
– Himanshu Jain
Jun 18 '16 at 11:25