{"id":46,"date":"2008-01-31T12:31:08","date_gmt":"2008-01-31T16:31:08","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=46"},"modified":"2008-07-23T11:40:48","modified_gmt":"2008-07-23T15:40:48","slug":"springnet","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=46","title":{"rendered":"Spring.Net Overview"},"content":{"rendered":"<p>Configure<\/p>\n<ul>\n<li>Add to References\n<ul>\n<li>Spring.Core.dll<\/li>\n<\/ul>\n<\/li>\n<li>Add to App.config or Web.config\n<pre lang=\"xml\">\r\n<sectionGroup name=\"spring\">\r\n  <section name=\"context\"\r\n    type=\"Spring.Context.Support\r\n            .ContextHandler,\r\n    Spring.Core\" \/>\r\n    <section name=\"objects\"\r\n    type=\"Spring.Context.Support\r\n            .DefaultSectionHandler,\r\n  Spring.Core\" \/>\r\n<\/sectionGroup>\r\n<\/pre>\n<\/li>\n<li>Define an object interface\n<pre lang=\"csharp\">\r\npublic interface ISimpleMessage\r\n{\r\nString Message { get; }\r\n}\r\n<\/pre>\n<\/li>\n<li>Do an implementation\n<pre lang=\"csharp\">\r\npublic class SimpleMessage  \r\n  : ISimpleMessage{\r\n  private String _message;\r\n  public SimpleMessage(){}\r\n  public SimpleMessage(String message)\r\n  {\r\n    _message = message;\r\n  }\r\n\r\n  public String Message\r\n  {\r\n    get { return _message; }\r\n    set { _message = value; }\r\n  }\r\n}<\/pre>\n<\/li>\n<li>Map objects in App.config\n<pre lang=\"xml\">\r\n<spring>\r\n<context>\r\n  <resource uri=\"config:\/\/spring\/objects\" \/>\r\n<\/context>\r\n<objects xmlns=\r\n  \"http:\/\/www.springframework.net\">\r\n  <!-- Messages -->\r\n  <object name=\"SimpleMessage\"\r\n    type=\"Test.Spring.SimpleMessage, \r\n    Test.Spring\"\r\n    singleton=\"false\">\r\n    <constructor-arg name=\"message\"\r\n    value=\"constructor-based injection.\" \/>\r\n  <\/object>\r\n  <object name=\"SimpleMessageByProperty\"\r\n    type=\"Test.Spring.SimpleMessage, \r\n      Test.Spring\"\r\n    singleton=\"false\">\r\n    <property name=\"Message\" \r\n      value=\"property-based injection.\" \/>\r\n  <\/object>\r\n<\/objects>\r\n<\/spring>\r\n<\/pre>\n<\/li>\n<li>Use\n<pre lang=\"csharp\">\r\nusing Spring.Context;\r\nusing Spring.Context.Support;\r\n\r\n...\r\n\r\nIApplicationContext ctx = \r\n  ContextRegistry.GetContext();\r\nISimpleMessage smsg = (ISimpleMessage) \r\n  ctx.GetObject(\"SimpleMessage\");\r\nlabel1.Text = smsg.Message;\r\n...<\/pre>\n<\/li>\n<li>Constructor injection\n<pre lang=\"xml\">\r\n<object name=\"SimpleMessage\"\r\n  type=\"Test.Spring.SimpleMessage, \r\n  Test.Spring\"\r\n  singleton=\"false\">\r\n  <constructor-arg name=\"message\"\r\n  value=\"constructor-based injection.\" \/>\r\n<\/object>\r\n<\/pre>\n<\/li>\n<li>Property injection\n<pre lang=\"xml\">\r\n<object name=\"SimpleMessageByProperty\"\r\n  type=\"Test.Spring.SimpleMessage, \r\n    Test.Spring\"\r\n  singleton=\"false\">\r\n  <property name=\"Message\" \r\n    value=\"property-based injection.\" \/>\r\n<\/object>\r\n<\/pre>\n<\/li>\n<li>IMessageSource\n<ul>\n<li>For retrieving localized resources\n<ul>\n<li>Text<\/li>\n<li>Image<\/li>\n<\/ul>\n<\/li>\n<li>Add a resouce file called TestResource.resx<\/li>\n<li>Add a resouce file called TestImages.resx<\/li>\n<li>Add to App.config<\/li>\n<pre lang=\"xml\">\r\n<object name=\"messageSource\" \r\n   type=\"Spring.Context.Support\r\n   .ResourceSetMessageSource, \r\n    Spring.Core\">\r\n  <property name=\"resourceManagers\">\r\n   <list>\r\n    <value>Test.Spring.TestImages, \r\n     Test.Spring<\/value>\r\n   <ref object=\"myResourceManager\" \/>\r\n    <\/list>\r\n  <\/property>\r\n<\/object>\r\n\r\n<object name=\"myResourceManager\" \r\n  type=\"Spring.Objects.Factory\r\n   .Config.ResourceManagerFactoryObject, \r\n   Spring.Core\">\r\n  <property name=\"baseName\" \r\n   value=\"Test.Spring.TestResource\" \/>\r\n  <property name=\"assemblyName\" \r\n   value=\"Test.Spring\" \/>\r\n<\/object>\r\n<\/pre>\n<li>Use\n<pre lang=\"csharp\">\r\n\/\/ Default culture\r\nlabel1.Text = ctx.GetMessage(\"FirstName\", \r\n  CultureInfo.CurrentCulture);\r\n\/\/Display spanish\r\nCultureInfo spanish = new CultureInfo(\"es\");\r\nlabel1.Text = \r\n  ctx.GetMessage(\"FirstName\", spanish);\r\n\/\/ Get image\r\npbxTest.Image = ctx.GetResourceObject(\r\n  \"Sunset\") as Image;\r\n<\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<p>References<\/p>\n<p><a target=\"_blank\" href=\"http:\/\/www.developer.com\/net\/csharp\/article.php\/10918_3722931_1\">Dependency Injection with Spring.Net<\/a><\/p>\n<pre><\/pre>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Configure Add to References Spring.Core.dll Add to App.config or Web.config Define an object interface public interface ISimpleMessage { String Message { get; } } Do an implementation public class SimpleMessage : ISimpleMessage{ private String _message; public SimpleMessage(){} public SimpleMessage(String message) &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=46\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5],"tags":[],"class_list":["post-46","post","type-post","status-publish","format-standard","hentry","category-c"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-K","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/46","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=46"}],"version-history":[{"count":0,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/46\/revisions"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=46"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=46"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}